Skip to content
Merged
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 @@ -74,6 +74,8 @@ pub mod string_tgt_unsafe;
pub mod unique_ptr_tgt_refcount;
#[path = r#"../unique_ptr/tgt_unsafe.rs"#]
pub mod unique_ptr_tgt_unsafe;
#[path = r#"../unistd/tgt_unsafe.rs"#]
pub mod unistd_tgt_unsafe;
#[path = r#"../vector/tgt_refcount.rs"#]
pub mod vector_tgt_refcount;
#[path = r#"../vector/tgt_unsafe.rs"#]
Expand Down
354 changes: 354 additions & 0 deletions rules/unistd/ir_unsafe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
{
"f1": {
"body": [
{
"text": "libc::close("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "i32"
}
},
"return_type": {
"type": "i32"
}
},
"f10": {
"body": [
{
"text": "libc::write("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 2,
"access": "read"
}
},
{
"text": " as usize) as i64"
}
],
"params": {
"a0": {
"type": "i32"
},
"a1": {
"type": "*const ::libc::c_void",
"is_unsafe_pointer": true
},
"a2": {
"type": "u64"
}
},
"return_type": {
"type": "i64"
}
},
"f11": {
"body": [
{
"text": "libc::rmdir("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": " as *const i8)"
}
],
"params": {
"a0": {
"type": "*const u8",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "i32"
}
},
"f2": {
"body": [
{
"text": "libc::lseek("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 2,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "i32"
},
"a1": {
"type": "i64"
},
"a2": {
"type": "i32"
}
},
"return_type": {
"type": "i64"
}
},
"f3": {
"body": [
{
"text": "libc::read("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 2,
"access": "read"
}
},
{
"text": " as usize) as i64"
}
],
"params": {
"a0": {
"type": "i32"
},
"a1": {
"type": "*mut ::libc::c_void",
"is_unsafe_pointer": true
},
"a2": {
"type": "u64"
}
},
"return_type": {
"type": "i64"
}
},
"f4": {
"body": [
{
"text": "libc::unlink("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": " as *const i8)"
}
],
"params": {
"a0": {
"type": "*const u8",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "i32"
}
},
"f5": {
"body": [
{
"text": "libc::pipe("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "*mut i32",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "i32"
}
},
"f6": {
"body": [
{
"text": "libc::ftruncate("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ", "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "i32"
},
"a1": {
"type": "i64"
}
},
"return_type": {
"type": "i32"
}
},
"f7": {
"body": [
{
"text": "libc::isatty("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": ")"
}
],
"params": {
"a0": {
"type": "i32"
}
},
"return_type": {
"type": "i32"
}
},
"f8": {
"body": [
{
"text": "libc::geteuid()"
}
],
"return_type": {
"type": "u32"
}
},
"f9": {
"body": [
{
"text": "libc::gethostname("
},
{
"placeholder": {
"arg": 0,
"access": "read"
}
},
{
"text": " as *mut i8, "
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": " as usize)"
}
],
"params": {
"a0": {
"type": "*mut u8",
"is_unsafe_pointer": true
},
"a1": {
"type": "u64"
}
},
"return_type": {
"type": "i32"
}
}
}
28 changes: 28 additions & 0 deletions rules/unistd/src.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

#include <unistd.h>

int f1(int fd) { return close(fd); }

off_t f2(int fd, off_t offset, int whence) { return lseek(fd, offset, whence); }

ssize_t f3(int fd, void *buf, size_t count) { return read(fd, buf, count); }

int f4(const char *pathname) { return unlink(pathname); }

int f5(int pipefd[2]) { return pipe(pipefd); }

int f6(int fd, off_t length) { return ftruncate(fd, length); }

int f7(int fd) { return isatty(fd); }

uid_t f8(void) { return geteuid(); }

int f9(char *name, size_t len) { return gethostname(name, len); }

ssize_t f10(int fd, const void *buf, size_t count) {
return write(fd, buf, count);
}

int f11(const char *pathname) { return rmdir(pathname); }
Loading
Loading