Skip to content

Commit 2da0aa2

Browse files
authored
[unsafe] Rules for locale, netdb, pwd, signal, termios (#134)
1 parent 656c792 commit 2da0aa2

16 files changed

Lines changed: 391 additions & 0 deletions

rules/locale/ir_unsafe.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"f1": {
3+
"body": [
4+
{
5+
"text": "libc::setlocale("
6+
},
7+
{
8+
"placeholder": {
9+
"arg": 0,
10+
"access": "read"
11+
}
12+
},
13+
{
14+
"text": ", "
15+
},
16+
{
17+
"placeholder": {
18+
"arg": 1,
19+
"access": "read"
20+
}
21+
},
22+
{
23+
"text": " as *const i8) as *mut u8"
24+
}
25+
],
26+
"params": {
27+
"a0": {
28+
"type": "i32"
29+
},
30+
"a1": {
31+
"type": "*const u8",
32+
"is_unsafe_pointer": true
33+
}
34+
},
35+
"return_type": {
36+
"type": "*mut u8",
37+
"is_unsafe_pointer": true
38+
}
39+
}
40+
}

rules/locale/src.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <locale.h>
5+
6+
char *f1(int category, const char *locale) {
7+
return setlocale(category, locale);
8+
}

rules/locale/tgt_unsafe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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, a1: *const u8) -> *mut u8 {
5+
libc::setlocale(a0, a1 as *const i8) as *mut u8
6+
}

rules/netdb/ir_unsafe.json

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"f1": {
3+
"body": [
4+
{
5+
"text": "libc::getaddrinfo("
6+
},
7+
{
8+
"placeholder": {
9+
"arg": 0,
10+
"access": "read"
11+
}
12+
},
13+
{
14+
"text": " as *const i8, "
15+
},
16+
{
17+
"placeholder": {
18+
"arg": 1,
19+
"access": "read"
20+
}
21+
},
22+
{
23+
"text": " as *const i8, "
24+
},
25+
{
26+
"placeholder": {
27+
"arg": 2,
28+
"access": "read"
29+
}
30+
},
31+
{
32+
"text": ", "
33+
},
34+
{
35+
"placeholder": {
36+
"arg": 3,
37+
"access": "read"
38+
}
39+
},
40+
{
41+
"text": ")"
42+
}
43+
],
44+
"params": {
45+
"a0": {
46+
"type": "*const u8",
47+
"is_unsafe_pointer": true
48+
},
49+
"a1": {
50+
"type": "*const u8",
51+
"is_unsafe_pointer": true
52+
},
53+
"a2": {
54+
"type": "*const ::libc::addrinfo",
55+
"is_unsafe_pointer": true
56+
},
57+
"a3": {
58+
"type": "*mut *mut ::libc::addrinfo",
59+
"is_unsafe_pointer": true
60+
}
61+
},
62+
"return_type": {
63+
"type": "i32"
64+
}
65+
},
66+
"f2": {
67+
"body": [
68+
{
69+
"text": "libc::freeaddrinfo("
70+
},
71+
{
72+
"placeholder": {
73+
"arg": 0,
74+
"access": "read"
75+
}
76+
},
77+
{
78+
"text": ")"
79+
}
80+
],
81+
"params": {
82+
"a0": {
83+
"type": "*mut ::libc::addrinfo",
84+
"is_unsafe_pointer": true
85+
}
86+
}
87+
}
88+
}

rules/netdb/src.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <netdb.h>
5+
6+
int f1(const char *node, const char *service, const struct addrinfo *hints,
7+
struct addrinfo **res) {
8+
return getaddrinfo(node, service, hints, res);
9+
}
10+
11+
void f2(struct addrinfo *res) { return freeaddrinfo(res); }

rules/netdb/tgt_unsafe.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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(
5+
a0: *const u8,
6+
a1: *const u8,
7+
a2: *const ::libc::addrinfo,
8+
a3: *mut *mut ::libc::addrinfo,
9+
) -> i32 {
10+
libc::getaddrinfo(a0 as *const i8, a1 as *const i8, a2, a3)
11+
}
12+
13+
unsafe fn f2(a0: *mut ::libc::addrinfo) {
14+
libc::freeaddrinfo(a0)
15+
}

rules/pwd/ir_unsafe.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"f1": {
3+
"body": [
4+
{
5+
"text": "libc::getpwuid("
6+
},
7+
{
8+
"placeholder": {
9+
"arg": 0,
10+
"access": "read"
11+
}
12+
},
13+
{
14+
"text": ")"
15+
}
16+
],
17+
"params": {
18+
"a0": {
19+
"type": "u32"
20+
}
21+
},
22+
"return_type": {
23+
"type": "*mut ::libc::passwd",
24+
"is_unsafe_pointer": true
25+
}
26+
}
27+
}

rules/pwd/src.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <pwd.h>
5+
6+
struct passwd *f1(uid_t uid) { return getpwuid(uid); }

rules/pwd/tgt_unsafe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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: u32) -> *mut ::libc::passwd {
5+
libc::getpwuid(a0)
6+
}

rules/signal/ir_unsafe.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"f1": {
3+
"body": [
4+
{
5+
"text": "libc::sigaction("
6+
},
7+
{
8+
"placeholder": {
9+
"arg": 0,
10+
"access": "read"
11+
}
12+
},
13+
{
14+
"text": ", "
15+
},
16+
{
17+
"placeholder": {
18+
"arg": 1,
19+
"access": "read"
20+
}
21+
},
22+
{
23+
"text": ", "
24+
},
25+
{
26+
"placeholder": {
27+
"arg": 2,
28+
"access": "read"
29+
}
30+
},
31+
{
32+
"text": ")"
33+
}
34+
],
35+
"params": {
36+
"a0": {
37+
"type": "i32"
38+
},
39+
"a1": {
40+
"type": "*const ::libc::sigaction",
41+
"is_unsafe_pointer": true
42+
},
43+
"a2": {
44+
"type": "*mut ::libc::sigaction",
45+
"is_unsafe_pointer": true
46+
}
47+
},
48+
"return_type": {
49+
"type": "i32"
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)