mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-28 12:30:22 +00:00
[sanitizer] Intercept if_indextoname() and if_nametoindex().
llvm-svn: 200945
This commit is contained in:
parent
2220dfadda
commit
4a03fa4f60
23
compiler-rt/lib/msan/lit_tests/if_indextoname.cc
Normal file
23
compiler-rt/lib/msan/lit_tests/if_indextoname.cc
Normal file
@ -0,0 +1,23 @@
|
||||
// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t 2>&1
|
||||
// RUN: %clangxx_msan -m64 -O0 -D_FILE_OFFSET_BITS=64 %s -o %t && %t 2>&1
|
||||
// RUN: %clangxx_msan -m64 -O3 %s -o %t && %t 2>&1
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sanitizer/msan_interface.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char ifname[IF_NAMESIZE + 1];
|
||||
assert(0 == __msan_test_shadow(ifname, sizeof(ifname)));
|
||||
if (!if_indextoname(1, ifname)) {
|
||||
assert(errno == ENXIO);
|
||||
printf("No network interfaces found.\n");
|
||||
return 0;
|
||||
}
|
||||
assert(strlen(ifname) + 1 == __msan_test_shadow(ifname, sizeof(ifname)));
|
||||
return 0;
|
||||
}
|
@ -3227,6 +3227,29 @@ INTERCEPTOR(int, getifaddrs, __sanitizer_ifaddrs **ifap) {
|
||||
#define INIT_GETIFADDRS
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_IF_INDEXTONAME
|
||||
INTERCEPTOR(char *, if_indextoname, unsigned int ifindex, char* ifname) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, if_indextoname, ifindex, ifname);
|
||||
char *res = REAL(if_indextoname)(ifindex, ifname);
|
||||
if (res && ifname)
|
||||
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ifname, REAL(strlen)(ifname) + 1);
|
||||
return res;
|
||||
}
|
||||
INTERCEPTOR(unsigned int, if_nametoindex, const char* ifname) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, if_nametoindex, ifname);
|
||||
if (ifname)
|
||||
COMMON_INTERCEPTOR_READ_RANGE(ctx, ifname, REAL(strlen)(ifname) + 1);
|
||||
return REAL(if_nametoindex)(ifname);
|
||||
}
|
||||
#define INIT_IF_INDEXTONAME \
|
||||
COMMON_INTERCEPT_FUNCTION(if_indextoname); \
|
||||
COMMON_INTERCEPT_FUNCTION(if_nametoindex);
|
||||
#else
|
||||
#define INIT_IF_INDEXTONAME
|
||||
#endif
|
||||
|
||||
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
|
||||
INIT_TEXTDOMAIN; \
|
||||
INIT_STRCMP; \
|
||||
@ -3346,5 +3369,6 @@ INTERCEPTOR(int, getifaddrs, __sanitizer_ifaddrs **ifap) {
|
||||
INIT_LISTXATTR; \
|
||||
INIT_GETXATTR; \
|
||||
INIT_GETRESID; \
|
||||
INIT_GETIFADDRS;
|
||||
INIT_GETIFADDRS; \
|
||||
INIT_IF_INDEXTONAME;
|
||||
/**/
|
||||
|
@ -183,5 +183,6 @@
|
||||
#define SANITIZER_INTERCEPT_GETXATTR SI_LINUX
|
||||
#define SANITIZER_INTERCEPT_GETRESID SI_LINUX
|
||||
#define SANITIZER_INTERCEPT_GETIFADDRS SI_LINUX_NOT_ANDROID | SI_MAC
|
||||
#define SANITIZER_INTERCEPT_IF_INDEXTONAME SI_LINUX_NOT_ANDROID | SI_MAC
|
||||
|
||||
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user