Skip to content

Commit 6d47225

Browse files
committed
Add rules for libc structs
1 parent 12c7116 commit 6d47225

26 files changed

Lines changed: 145 additions & 17 deletions

rules/dirent/src.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <dirent.h>
55

66
using t1 = DIR *;
7+
using t2 = struct dirent;
78

89
DIR *f1(const char *name) { return opendir(name); }
910

rules/dirent/tgt_unsafe.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ fn t1() -> *mut ::libc::DIR {
55
std::ptr::null_mut()
66
}
77

8+
fn t2() -> ::libc::dirent {
9+
unsafe { std::mem::zeroed() }
10+
}
11+
812
unsafe fn f1(a0: *const libc::c_char) -> *mut ::libc::DIR {
913
libc::opendir(a0)
1014
}

rules/ifaddrs/src.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <sys/types.h>
22
#include <ifaddrs.h>
33

4+
typedef struct ifaddrs t1;
5+
46
int f1(struct ifaddrs **ifap) {
57
return getifaddrs(ifap);
68
}

rules/ifaddrs/tgt_unsafe.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
fn t1() -> libc::ifaddrs {
2+
unsafe { std::mem::zeroed() }
3+
}
4+
15
unsafe fn f1(a0: *mut *mut libc::ifaddrs) -> i32 {
26
libc::getifaddrs(a0)
37
}

rules/ip/src.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#include <netinet/in.h>
22

3+
typedef struct sockaddr_in t1;
4+
typedef struct in_addr t2;
5+
typedef struct sockaddr_in6 t3;
6+
typedef struct in6_addr t4;
7+
38
int f1() {
49
return IPPROTO_TCP;
510
}

rules/ip/tgt_unsafe.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
fn t1() -> ::libc::sockaddr_in {
2+
unsafe { std::mem::zeroed() }
3+
}
4+
5+
fn t2() -> ::libc::in_addr {
6+
unsafe { std::mem::zeroed() }
7+
}
8+
9+
fn t3() -> ::libc::sockaddr_in6 {
10+
unsafe { std::mem::zeroed() }
11+
}
12+
13+
fn t4() -> ::libc::in6_addr {
14+
unsafe { std::mem::zeroed() }
15+
}
16+
117
unsafe fn f1() -> i32 {
218
libc::IPPROTO_TCP
319
}

rules/netdb/src.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <netdb.h>
55

6+
typedef struct addrinfo t1;
7+
68
int f1(const char *node, const char *service, const struct addrinfo *hints,
79
struct addrinfo **res) {
810
return getaddrinfo(node, service, hints, res);

rules/netdb/tgt_unsafe.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4+
fn t1() -> ::libc::addrinfo {
5+
unsafe { std::mem::zeroed() }
6+
}
7+
48
unsafe fn f1(
59
a0: *const libc::c_char,
610
a1: *const libc::c_char,

rules/poll/src.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <poll.h>
55

6+
typedef struct pollfd t1;
7+
68
int f1(struct pollfd *fds, nfds_t nfds, int timeout) {
79
return poll(fds, nfds, timeout);
810
}

rules/poll/tgt_unsafe.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4+
fn t1() -> ::libc::pollfd {
5+
unsafe { std::mem::zeroed() }
6+
}
7+
48
unsafe fn f1(a0: *mut ::libc::pollfd, a1: u64, a2: i32) -> i32 {
59
libc::poll(a0, a1 as ::libc::nfds_t, a2)
610
}

0 commit comments

Comments
 (0)