Skip to content

Commit bbfc459

Browse files
authored
[unsafe] Rules for arpa_inet, cstdlib, cstring, socket, time, xattr (#137)
1 parent 2611835 commit bbfc459

18 files changed

Lines changed: 967 additions & 0 deletions

File tree

rules/arpa_inet/ir_unsafe.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,53 @@
4646
"return_type": {
4747
"type": "u16"
4848
}
49+
},
50+
"f3": {
51+
"body": [
52+
{
53+
"text": "u16::to_be("
54+
},
55+
{
56+
"placeholder": {
57+
"arg": 0,
58+
"access": "read"
59+
}
60+
},
61+
{
62+
"text": ")"
63+
}
64+
],
65+
"params": {
66+
"a0": {
67+
"type": "u16"
68+
}
69+
},
70+
"return_type": {
71+
"type": "u16"
72+
}
73+
},
74+
"f4": {
75+
"body": [
76+
{
77+
"text": "u32::to_be("
78+
},
79+
{
80+
"placeholder": {
81+
"arg": 0,
82+
"access": "read"
83+
}
84+
},
85+
{
86+
"text": ")"
87+
}
88+
],
89+
"params": {
90+
"a0": {
91+
"type": "u32"
92+
}
93+
},
94+
"return_type": {
95+
"type": "u32"
96+
}
4997
}
5098
}

rules/arpa_inet/src.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55

66
uint32_t f1(uint32_t x) { return ntohl(x); }
77
uint16_t f2(uint16_t x) { return ntohs(x); }
8+
uint16_t f3(uint16_t x) { return htons(x); }
9+
uint32_t f4(uint32_t x) { return htonl(x); }

rules/arpa_inet/tgt_unsafe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ unsafe fn f1(a0: u32) -> u32 {
77
unsafe fn f2(a0: u16) -> u16 {
88
u16::from_be(a0)
99
}
10+
unsafe fn f3(a0: u16) -> u16 {
11+
u16::to_be(a0)
12+
}
13+
unsafe fn f4(a0: u32) -> u32 {
14+
u32::to_be(a0)
15+
}

rules/cstdlib/ir_unsafe.json

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,138 @@
203203
"return_type": {
204204
"type": "i32"
205205
}
206+
},
207+
"f8": {
208+
"body": [
209+
{
210+
"text": "libc::bsearch(\n "
211+
},
212+
{
213+
"placeholder": {
214+
"arg": 0,
215+
"access": "read"
216+
}
217+
},
218+
{
219+
"text": ",\n "
220+
},
221+
{
222+
"placeholder": {
223+
"arg": 1,
224+
"access": "read"
225+
}
226+
},
227+
{
228+
"text": ",\n "
229+
},
230+
{
231+
"placeholder": {
232+
"arg": 2,
233+
"access": "read"
234+
}
235+
},
236+
{
237+
"text": " as ::libc::size_t,\n "
238+
},
239+
{
240+
"placeholder": {
241+
"arg": 3,
242+
"access": "read"
243+
}
244+
},
245+
{
246+
"text": " as ::libc::size_t,\n Some(std::mem::transmute::<\n *const (),\n unsafe extern \"C\" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,\n >("
247+
},
248+
{
249+
"placeholder": {
250+
"arg": 4,
251+
"access": "read"
252+
}
253+
},
254+
{
255+
"text": " as *const ())),\n )"
256+
}
257+
],
258+
"params": {
259+
"a0": {
260+
"type": "*const ::libc::c_void",
261+
"is_unsafe_pointer": true
262+
},
263+
"a1": {
264+
"type": "*const ::libc::c_void",
265+
"is_unsafe_pointer": true
266+
},
267+
"a2": {
268+
"type": "u64"
269+
},
270+
"a3": {
271+
"type": "u64"
272+
},
273+
"a4": {
274+
"type": "unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32"
275+
}
276+
},
277+
"return_type": {
278+
"type": "*mut ::libc::c_void",
279+
"is_unsafe_pointer": true
280+
}
281+
},
282+
"f9": {
283+
"body": [
284+
{
285+
"text": "libc::qsort(\n "
286+
},
287+
{
288+
"placeholder": {
289+
"arg": 0,
290+
"access": "read"
291+
}
292+
},
293+
{
294+
"text": ",\n "
295+
},
296+
{
297+
"placeholder": {
298+
"arg": 1,
299+
"access": "read"
300+
}
301+
},
302+
{
303+
"text": " as ::libc::size_t,\n "
304+
},
305+
{
306+
"placeholder": {
307+
"arg": 2,
308+
"access": "read"
309+
}
310+
},
311+
{
312+
"text": " as ::libc::size_t,\n Some(std::mem::transmute::<\n *const (),\n unsafe extern \"C\" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,\n >("
313+
},
314+
{
315+
"placeholder": {
316+
"arg": 3,
317+
"access": "read"
318+
}
319+
},
320+
{
321+
"text": " as *const ())),\n )"
322+
}
323+
],
324+
"params": {
325+
"a0": {
326+
"type": "*mut ::libc::c_void",
327+
"is_unsafe_pointer": true
328+
},
329+
"a1": {
330+
"type": "u64"
331+
},
332+
"a2": {
333+
"type": "u64"
334+
},
335+
"a3": {
336+
"type": "unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32"
337+
}
338+
}
206339
}
207340
}

rules/cstdlib/src.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ char *f6(const char *name) { return getenv(name); }
1818
int f7(const char *name, const char *value, int overwrite) {
1919
return setenv(name, value, overwrite);
2020
}
21+
22+
void *f8(const void *key, const void *base, size_t nmemb, size_t size,
23+
int (*compar)(const void *, const void *)) {
24+
return bsearch(key, base, nmemb, size, compar);
25+
}
26+
27+
void f9(void *base, size_t nmemb, size_t size,
28+
int (*compar)(const void *, const void *)) {
29+
return qsort(base, nmemb, size, compar);
30+
}

rules/cstdlib/tgt_unsafe.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,39 @@ unsafe fn f6(a0: *const u8) -> *mut u8 {
2828
unsafe fn f7(a0: *const u8, a1: *const u8, a2: i32) -> i32 {
2929
libc::setenv(a0 as *const i8, a1 as *const i8, a2)
3030
}
31+
32+
unsafe fn f8(
33+
a0: *const ::libc::c_void,
34+
a1: *const ::libc::c_void,
35+
a2: u64,
36+
a3: u64,
37+
a4: unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,
38+
) -> *mut ::libc::c_void {
39+
libc::bsearch(
40+
a0,
41+
a1,
42+
a2 as ::libc::size_t,
43+
a3 as ::libc::size_t,
44+
Some(std::mem::transmute::<
45+
*const (),
46+
unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,
47+
>(a4 as *const ())),
48+
)
49+
}
50+
51+
unsafe fn f9(
52+
a0: *mut ::libc::c_void,
53+
a1: u64,
54+
a2: u64,
55+
a3: unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,
56+
) {
57+
libc::qsort(
58+
a0,
59+
a1 as ::libc::size_t,
60+
a2 as ::libc::size_t,
61+
Some(std::mem::transmute::<
62+
*const (),
63+
unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32,
64+
>(a3 as *const ())),
65+
)
66+
}

0 commit comments

Comments
 (0)