Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rules/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub mod stdio_tgt_unsafe;
pub mod string_tgt_refcount;
#[path = r#"../string/tgt_unsafe.rs"#]
pub mod string_tgt_unsafe;
#[path = r#"../time/tgt_unsafe.rs"#]
pub mod time_tgt_unsafe;
#[path = r#"../unique_ptr/tgt_refcount.rs"#]
pub mod unique_ptr_tgt_refcount;
#[path = r#"../unique_ptr/tgt_unsafe.rs"#]
Expand Down
281 changes: 281 additions & 0 deletions rules/time/ir_unsafe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
{
"f1": {
"body": [
{
"text": "libc::time("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "*mut i64",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "i64"
}
},
"f2": {
"body": [
{
"text": "libc::gettimeofday("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": " as *mut ::libc::timezone)"
}
],
"params": {
"a0": {
"type": "*mut ::libc::timeval",
"is_unsafe_pointer": true
},
"a1": {
"type": "*mut ::libc::timezone",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "i32"
}
},
"f3": {
"body": [
{
"text": "libc::clock_gettime("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": " as ::libc::clockid_t, "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "::libc::clockid_t"
},
"a1": {
"type": "*mut ::libc::timespec",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "i32"
}
},
"f4": {
"body": [
{
"text": "libc::localtime_r("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "*const i64",
"is_unsafe_pointer": true
},
"a1": {
"type": "*mut ::libc::tm",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "*mut ::libc::tm",
"is_unsafe_pointer": true
}
},
"f5": {
"body": [
{
"text": "libc::gmtime_r("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "*const i64",
"is_unsafe_pointer": true
},
"a1": {
"type": "*mut ::libc::tm",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "*mut ::libc::tm",
"is_unsafe_pointer": true
}
},
"f6": {
"body": [
{
"text": "libc::strftime("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": " as *mut i8, "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": " as usize, "
},
{
"placeholder": {
"arg": 2,
"access": "read"
}
},
{
"text": " as *const i8, "
},
{
"placeholder": {
"arg": 3,
"access": "read"
}
},
{
"text": ") as u64"
}
],
"params": {
"a0": {
"type": "*mut u8",
"is_unsafe_pointer": true
},
"a1": {
"type": "u64"
},
"a2": {
"type": "*const u8",
"is_unsafe_pointer": true
},
"a3": {
"type": "*const ::libc::tm",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "u64"
}
},
"f7": {
"body": [
{
"text": "libc::utimes("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": " as *const i8, "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "*const u8",
"is_unsafe_pointer": true
},
"a1": {
"type": "*const ::libc::timeval",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "i32"
}
}
}
29 changes: 29 additions & 0 deletions rules/time/src.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

#include <sys/time.h>
#include <time.h>

time_t f1(time_t *tloc) { return time(tloc); }

int f2(struct timeval *tv, struct timezone *tz) {
return gettimeofday(tv, tz);
}

int f3(clockid_t clk_id, struct timespec *tp) { return clock_gettime(clk_id, tp); }

struct tm *f4(const time_t *timep, struct tm *result) {
return localtime_r(timep, result);
}

struct tm *f5(const time_t *timep, struct tm *result) {
return gmtime_r(timep, result);
}

size_t f6(char *s, size_t max, const char *fmt, const struct tm *tm) {
return strftime(s, max, fmt, tm);
}

int f7(const char *filename, const struct timeval times[2]) {
return utimes(filename, times);
}
30 changes: 30 additions & 0 deletions rules/time/tgt_unsafe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

unsafe fn f1(a0: *mut i64) -> i64 {
libc::time(a0)
}

unsafe fn f2(a0: *mut ::libc::timeval, a1: *mut ::libc::timezone) -> i32 {
libc::gettimeofday(a0, a1 as *mut ::libc::timezone)
}

unsafe fn f3(a0: ::libc::clockid_t, a1: *mut ::libc::timespec) -> i32 {
libc::clock_gettime(a0 as ::libc::clockid_t, a1)
}

unsafe fn f4(a0: *const i64, a1: *mut ::libc::tm) -> *mut ::libc::tm {
libc::localtime_r(a0, a1)
}

unsafe fn f5(a0: *const i64, a1: *mut ::libc::tm) -> *mut ::libc::tm {
libc::gmtime_r(a0, a1)
}

unsafe fn f6(a0: *mut u8, a1: u64, a2: *const u8, a3: *const ::libc::tm) -> u64 {
libc::strftime(a0 as *mut i8, a1 as usize, a2 as *const i8, a3) as u64
}

unsafe fn f7(a0: *const u8, a1: *const ::libc::timeval) -> i32 {
libc::utimes(a0 as *const i8, a1)
}
Loading
Loading