[PATCH] [Msan] Fix the if_indextoname.cc test to pass on FreeBSD

Viktor Kutuzov vkutuzov at accesssoftek.com
Sat May 2 08:55:24 PDT 2015


Hi kcc, samsonov, eugenis,

On FreeBSD if_indextoname() leverages strncpy() that unpoisons the whole name buffer, what in turn results in the assertion following the if_indextoname() call to fail:
```
  if (!if_indextoname(1, ifname)) {
    ...
  }
  assert(strlen(ifname) + 1 == __msan_test_shadow(ifname, sizeof(ifname)));
```

http://reviews.llvm.org/D9456

Files:
  lib/msan/msan_interceptors.cc
  lib/sanitizer_common/sanitizer_platform_interceptors.h

Index: lib/msan/msan_interceptors.cc
===================================================================
--- lib/msan/msan_interceptors.cc
+++ lib/msan/msan_interceptors.cc
@@ -309,7 +309,8 @@
     copy_size++;  // trailing \0
   char *res = REAL(strncpy)(dest, src, n);  // NOLINT
   CopyShadowAndOrigin(dest, src, copy_size, &stack);
-  __msan_unpoison(dest + copy_size, n - copy_size);
+  if (!IsInInterceptorScope())
+    __msan_unpoison(dest + copy_size, n - copy_size);
   return res;
 }
 
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -223,7 +223,8 @@
 #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
+#define SANITIZER_INTERCEPT_IF_INDEXTONAME \
+  SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_MAC
 #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_AEABI_MEM SI_LINUX && defined(__arm__)
 #define SANITIZER_INTERCEPT___BZERO SI_MAC

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9456.24855.patch
Type: text/x-patch
Size: 1267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150502/7f47c30b/attachment.bin>


More information about the llvm-commits mailing list