[compiler-rt] r177065 - [msan] Intercept readdir64.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Thu Mar 14 05:49:23 PDT 2013
Author: eugenis
Date: Thu Mar 14 07:49:23 2013
New Revision: 177065
URL: http://llvm.org/viewvc/llvm-project?rev=177065&view=rev
Log:
[msan] Intercept readdir64.
Added:
compiler-rt/trunk/lib/msan/lit_tests/readdir64.cc (with props)
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/msan/tests/msan_test.cc
Added: compiler-rt/trunk/lib/msan/lit_tests/readdir64.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/readdir64.cc?rev=177065&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/readdir64.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/readdir64.cc Thu Mar 14 07:49:23 2013
@@ -0,0 +1,27 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O1 %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O2 %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && %t
+
+// RUN: %clangxx_msan -m64 -O0 -D_FILE_OFFSET_BITS=64 %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O1 -D_FILE_OFFSET_BITS=64 %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O2 -D_FILE_OFFSET_BITS=64 %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O3 -D_FILE_OFFSET_BITS=64 %s -o %t && %t
+
+// Test that readdir64 is intercepted as well as readdir.
+
+#include <sys/types.h>
+#include <dirent.h>
+#include <stdlib.h>
+
+
+int main(void) {
+ DIR *dir = opendir(".");
+ struct dirent *d = readdir(dir);
+ if (d->d_name[0]) {
+ closedir(dir);
+ exit(0);
+ }
+ closedir(dir);
+ return 0;
+}
Propchange: compiler-rt/trunk/lib/msan/lit_tests/readdir64.cc
------------------------------------------------------------------------------
svn:eol-style = LF
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=177065&r1=177064&r2=177065&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Mar 14 07:49:23 2013
@@ -91,6 +91,13 @@ INTERCEPTOR(void *, readdir, void *a) {
return res;
}
+INTERCEPTOR(void *, readdir64, void *a) {
+ ENSURE_MSAN_INITED();
+ void *res = REAL(readdir)(a);
+ __msan_unpoison(res, __sanitizer::struct_dirent64_sz);
+ return res;
+}
+
INTERCEPTOR(void *, memcpy, void *dest, const void *src, SIZE_T n) {
return __msan_memcpy(dest, src, n);
}
@@ -983,6 +990,7 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(fread_unlocked);
INTERCEPT_FUNCTION(readlink);
INTERCEPT_FUNCTION(readdir);
+ INTERCEPT_FUNCTION(readdir64);
INTERCEPT_FUNCTION(memcpy);
INTERCEPT_FUNCTION(memset);
INTERCEPT_FUNCTION(memmove);
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=177065&r1=177064&r2=177065&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu Mar 14 07:49:23 2013
@@ -35,6 +35,8 @@
#include <sys/utsname.h>
#include <sys/mman.h>
#include <sys/vfs.h>
+#include <sys/types.h>
+#include <dirent.h>
#if defined(__i386__) || defined(__x86_64__)
# include <emmintrin.h>
@@ -613,6 +615,14 @@ TEST(MemorySanitizer, getcwd_gnu) {
free(res);
}
+TEST(MemorySanitizer, readdir) {
+ DIR *dir = opendir(".");
+ struct dirent *d = readdir(dir);
+ assert(d);
+ EXPECT_NOT_POISONED(d->d_name[0]);
+ closedir(dir);
+}
+
TEST(MemorySanitizer, realpath) {
const char* relpath = ".";
char path[PATH_MAX + 1];
More information about the llvm-commits
mailing list