Skip to content

Commit dc64a51

Browse files
committed
Add unistd rules
1 parent 37693c6 commit dc64a51

5 files changed

Lines changed: 1042 additions & 0 deletions

File tree

rules/unistd/ir_unsafe.json

Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
{
2+
"f1": {
3+
"body": [
4+
{
5+
"text": "libc::close("
6+
},
7+
{
8+
"placeholder": {
9+
"arg": 0,
10+
"access": "read"
11+
}
12+
},
13+
{
14+
"text": ")"
15+
}
16+
],
17+
"params": {
18+
"a0": {
19+
"type": "i32"
20+
}
21+
},
22+
"return_type": {
23+
"type": "i32"
24+
}
25+
},
26+
"f10": {
27+
"body": [
28+
{
29+
"text": "libc::write("
30+
},
31+
{
32+
"placeholder": {
33+
"arg": 0,
34+
"access": "read"
35+
}
36+
},
37+
{
38+
"text": ", "
39+
},
40+
{
41+
"placeholder": {
42+
"arg": 1,
43+
"access": "read"
44+
}
45+
},
46+
{
47+
"text": ", "
48+
},
49+
{
50+
"placeholder": {
51+
"arg": 2,
52+
"access": "read"
53+
}
54+
},
55+
{
56+
"text": " as usize) as i64"
57+
}
58+
],
59+
"params": {
60+
"a0": {
61+
"type": "i32"
62+
},
63+
"a1": {
64+
"type": "*const ::libc::c_void",
65+
"is_unsafe_pointer": true
66+
},
67+
"a2": {
68+
"type": "u64"
69+
}
70+
},
71+
"return_type": {
72+
"type": "i64"
73+
}
74+
},
75+
"f2": {
76+
"body": [
77+
{
78+
"text": "libc::lseek("
79+
},
80+
{
81+
"placeholder": {
82+
"arg": 0,
83+
"access": "read"
84+
}
85+
},
86+
{
87+
"text": ", "
88+
},
89+
{
90+
"placeholder": {
91+
"arg": 1,
92+
"access": "read"
93+
}
94+
},
95+
{
96+
"text": ", "
97+
},
98+
{
99+
"placeholder": {
100+
"arg": 2,
101+
"access": "read"
102+
}
103+
},
104+
{
105+
"text": ")"
106+
}
107+
],
108+
"params": {
109+
"a0": {
110+
"type": "i32"
111+
},
112+
"a1": {
113+
"type": "i64"
114+
},
115+
"a2": {
116+
"type": "i32"
117+
}
118+
},
119+
"return_type": {
120+
"type": "i64"
121+
}
122+
},
123+
"f3": {
124+
"body": [
125+
{
126+
"text": "libc::read("
127+
},
128+
{
129+
"placeholder": {
130+
"arg": 0,
131+
"access": "read"
132+
}
133+
},
134+
{
135+
"text": ", "
136+
},
137+
{
138+
"placeholder": {
139+
"arg": 1,
140+
"access": "read"
141+
}
142+
},
143+
{
144+
"text": ", "
145+
},
146+
{
147+
"placeholder": {
148+
"arg": 2,
149+
"access": "read"
150+
}
151+
},
152+
{
153+
"text": " as usize) as i64"
154+
}
155+
],
156+
"params": {
157+
"a0": {
158+
"type": "i32"
159+
},
160+
"a1": {
161+
"type": "*mut ::libc::c_void",
162+
"is_unsafe_pointer": true
163+
},
164+
"a2": {
165+
"type": "u64"
166+
}
167+
},
168+
"return_type": {
169+
"type": "i64"
170+
}
171+
},
172+
"f4": {
173+
"body": [
174+
{
175+
"text": "libc::unlink("
176+
},
177+
{
178+
"placeholder": {
179+
"arg": 0,
180+
"access": "read"
181+
}
182+
},
183+
{
184+
"text": " as *const i8)"
185+
}
186+
],
187+
"params": {
188+
"a0": {
189+
"type": "*const u8",
190+
"is_unsafe_pointer": true
191+
}
192+
},
193+
"return_type": {
194+
"type": "i32"
195+
}
196+
},
197+
"f5": {
198+
"body": [
199+
{
200+
"text": "libc::pipe("
201+
},
202+
{
203+
"placeholder": {
204+
"arg": 0,
205+
"access": "read"
206+
}
207+
},
208+
{
209+
"text": ")"
210+
}
211+
],
212+
"params": {
213+
"a0": {
214+
"type": "*mut i32",
215+
"is_unsafe_pointer": true
216+
}
217+
},
218+
"return_type": {
219+
"type": "i32"
220+
}
221+
},
222+
"f6": {
223+
"body": [
224+
{
225+
"text": "libc::ftruncate("
226+
},
227+
{
228+
"placeholder": {
229+
"arg": 0,
230+
"access": "read"
231+
}
232+
},
233+
{
234+
"text": ", "
235+
},
236+
{
237+
"placeholder": {
238+
"arg": 1,
239+
"access": "read"
240+
}
241+
},
242+
{
243+
"text": ")"
244+
}
245+
],
246+
"params": {
247+
"a0": {
248+
"type": "i32"
249+
},
250+
"a1": {
251+
"type": "i64"
252+
}
253+
},
254+
"return_type": {
255+
"type": "i32"
256+
}
257+
},
258+
"f7": {
259+
"body": [
260+
{
261+
"text": "libc::isatty("
262+
},
263+
{
264+
"placeholder": {
265+
"arg": 0,
266+
"access": "read"
267+
}
268+
},
269+
{
270+
"text": ")"
271+
}
272+
],
273+
"params": {
274+
"a0": {
275+
"type": "i32"
276+
}
277+
},
278+
"return_type": {
279+
"type": "i32"
280+
}
281+
},
282+
"f8": {
283+
"body": [
284+
{
285+
"text": "libc::geteuid()"
286+
}
287+
],
288+
"return_type": {
289+
"type": "u32"
290+
}
291+
},
292+
"f9": {
293+
"body": [
294+
{
295+
"text": "libc::gethostname("
296+
},
297+
{
298+
"placeholder": {
299+
"arg": 0,
300+
"access": "read"
301+
}
302+
},
303+
{
304+
"text": " as *mut i8, "
305+
},
306+
{
307+
"placeholder": {
308+
"arg": 1,
309+
"access": "read"
310+
}
311+
},
312+
{
313+
"text": " as usize)"
314+
}
315+
],
316+
"params": {
317+
"a0": {
318+
"type": "*mut u8",
319+
"is_unsafe_pointer": true
320+
},
321+
"a1": {
322+
"type": "u64"
323+
}
324+
},
325+
"return_type": {
326+
"type": "i32"
327+
}
328+
}
329+
}

rules/unistd/src.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <unistd.h>
5+
6+
int f1(int fd) { return close(fd); }
7+
8+
off_t f2(int fd, off_t offset, int whence) { return lseek(fd, offset, whence); }
9+
10+
ssize_t f3(int fd, void *buf, size_t count) { return read(fd, buf, count); }
11+
12+
int f4(const char *pathname) { return unlink(pathname); }
13+
14+
int f5(int pipefd[2]) { return pipe(pipefd); }
15+
16+
int f6(int fd, off_t length) { return ftruncate(fd, length); }
17+
18+
int f7(int fd) { return isatty(fd); }
19+
20+
uid_t f8(void) { return geteuid(); }
21+
22+
int f9(char *name, size_t len) { return gethostname(name, len); }
23+
24+
ssize_t f10(int fd, const void *buf, size_t count) {
25+
return write(fd, buf, count);
26+
}

rules/unistd/tgt_unsafe.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe fn f1(a0: i32) -> i32 {
5+
libc::close(a0)
6+
}
7+
8+
unsafe fn f2(a0: i32, a1: i64, a2: i32) -> i64 {
9+
libc::lseek(a0, a1, a2)
10+
}
11+
12+
unsafe fn f3(a0: i32, a1: *mut ::libc::c_void, a2: u64) -> i64 {
13+
libc::read(a0, a1, a2 as usize) as i64
14+
}
15+
16+
unsafe fn f4(a0: *const u8) -> i32 {
17+
libc::unlink(a0 as *const i8)
18+
}
19+
20+
unsafe fn f5(a0: *mut i32) -> i32 {
21+
libc::pipe(a0)
22+
}
23+
24+
unsafe fn f6(a0: i32, a1: i64) -> i32 {
25+
libc::ftruncate(a0, a1)
26+
}
27+
28+
unsafe fn f7(a0: i32) -> i32 {
29+
libc::isatty(a0)
30+
}
31+
32+
unsafe fn f8() -> u32 {
33+
libc::geteuid()
34+
}
35+
36+
unsafe fn f9(a0: *mut u8, a1: u64) -> i32 {
37+
libc::gethostname(a0 as *mut i8, a1 as usize)
38+
}
39+
40+
unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: u64) -> i64 {
41+
libc::write(a0, a1, a2 as usize) as i64
42+
}

0 commit comments

Comments
 (0)