[sanitizer] Intercept if_indextoname() and if_nametoindex().

llvm-svn: 200945
This commit is contained in:
Sergey Matveev 2014-02-06 20:39:33 +00:00
parent 2220dfadda
commit 4a03fa4f60
3 changed files with 49 additions and 1 deletions

View 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;
}

View File

@ -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;
/**/

View File

@ -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