Index: compiler-rt/trunk/lib/msan/msan_interceptors.cc =================================================================== --- compiler-rt/trunk/lib/msan/msan_interceptors.cc +++ compiler-rt/trunk/lib/msan/msan_interceptors.cc @@ -703,7 +703,15 @@ #define MSAN_MAYBE_INTERCEPT___FXSTAT64 #endif -#if !SANITIZER_FREEBSD +#if SANITIZER_FREEBSD +INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) { + ENSURE_MSAN_INITED(); + int res = REAL(fstatat)(fd, pathname, buf, flags); + if (!res) __msan_unpoison(buf, __sanitizer::struct_stat_sz); + return res; +} +# define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(fstatat) +#else INTERCEPTOR(int, __fxstatat, int magic, int fd, char *pathname, void *buf, int flags) { ENSURE_MSAN_INITED(); @@ -711,9 +719,7 @@ if (!res) __msan_unpoison(buf, __sanitizer::struct_stat_sz); return res; } -#define MSAN_MAYBE_INTERCEPT___FXSTATAT INTERCEPT_FUNCTION(__fxstatat) -#else -#define MSAN_MAYBE_INTERCEPT___FXSTATAT +# define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(__fxstatat) #endif #if !SANITIZER_FREEBSD @@ -729,7 +735,16 @@ #define MSAN_MAYBE_INTERCEPT___FXSTATAT64 #endif -#if !SANITIZER_FREEBSD +#if SANITIZER_FREEBSD +INTERCEPTOR(int, stat, char *path, void *buf) { + ENSURE_MSAN_INITED(); + int res = REAL(stat)(path, buf); + if (!res) + __msan_unpoison(buf, __sanitizer::struct_stat_sz); + return res; +} +# define MSAN_INTERCEPT_STAT INTERCEPT_FUNCTION(stat) +#else INTERCEPTOR(int, __xstat, int magic, char *path, void *buf) { ENSURE_MSAN_INITED(); int res = REAL(__xstat)(magic, path, buf); @@ -737,9 +752,7 @@ __msan_unpoison(buf, __sanitizer::struct_stat_sz); return res; } -#define MSAN_MAYBE_INTERCEPT___XSTAT INTERCEPT_FUNCTION(__xstat) -#else -#define MSAN_MAYBE_INTERCEPT___XSTAT +# define MSAN_INTERCEPT_STAT INTERCEPT_FUNCTION(__xstat) #endif #if !SANITIZER_FREEBSD @@ -1634,8 +1647,8 @@ INTERCEPT_FUNCTION(gettimeofday); INTERCEPT_FUNCTION(fcvt); MSAN_MAYBE_INTERCEPT___FXSTAT; - MSAN_MAYBE_INTERCEPT___FXSTATAT; - MSAN_MAYBE_INTERCEPT___XSTAT; + MSAN_INTERCEPT_FSTATAT; + MSAN_INTERCEPT_STAT; MSAN_MAYBE_INTERCEPT___LXSTAT; MSAN_MAYBE_INTERCEPT___FXSTAT64; MSAN_MAYBE_INTERCEPT___FXSTATAT64; Index: compiler-rt/trunk/lib/msan/tests/msan_test.cc =================================================================== --- compiler-rt/trunk/lib/msan/tests/msan_test.cc +++ compiler-rt/trunk/lib/msan/tests/msan_test.cc @@ -76,8 +76,12 @@ // On FreeBSD procfs is not enabled by default. #if defined(__FreeBSD__) # define FILE_TO_READ "/bin/cat" +# define DIR_TO_READ "/bin" +# define SUBFILE_TO_READ "cat" #else # define FILE_TO_READ "/proc/self/stat" +# define DIR_TO_READ "/proc/self" +# define SUBFILE_TO_READ "stat" #endif static const size_t kPageSize = 4096; @@ -680,9 +684,9 @@ TEST(MemorySanitizer, fstatat) { struct stat* st = new struct stat; - int dirfd = open("/proc/self", O_RDONLY); + int dirfd = open(DIR_TO_READ, O_RDONLY); ASSERT_GT(dirfd, 0); - int res = fstatat(dirfd, "stat", st, 0); + int res = fstatat(dirfd, SUBFILE_TO_READ, st, 0); ASSERT_EQ(0, res); EXPECT_NOT_POISONED(st->st_dev); EXPECT_NOT_POISONED(st->st_mode);