diff options
author | Kamil Rytarowski <n54@gmx.com> | 2018-01-03 22:28:39 +0000 |
---|---|---|
committer | Kamil Rytarowski <n54@gmx.com> | 2018-01-03 22:28:39 +0000 |
commit | 31abb45803d272b3fd211253f571047256ab2f19 (patch) | |
tree | 62215dc514e0b69afcddf2e390a6eb4484a3e80a /compiler-rt | |
parent | cf524a408a4343d89b3fa7a3df535dba80116e13 (diff) | |
download | bcm5719-llvm-31abb45803d272b3fd211253f571047256ab2f19.tar.gz bcm5719-llvm-31abb45803d272b3fd211253f571047256ab2f19.zip |
Add MSan interceptor for fstat(2)
Summary:
Add new MSan interceptor that corrects NetBSD's
specific handling of fstat(2).
NetBSD renames the call to __fstat50.
Add new test: test/msan/fstat.cc
Sponsored by <The NetBSD Foundation>
Reviewers: joerg, eugenis, vitalybuka
Reviewed By: vitalybuka
Subscribers: llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D41637
llvm-svn: 321765
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/msan/msan_interceptors.cc | 15 | ||||
-rw-r--r-- | compiler-rt/test/msan/fstat.cc | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc index a7fe09b25ff..02b41efdaca 100644 --- a/compiler-rt/lib/msan/msan_interceptors.cc +++ b/compiler-rt/lib/msan/msan_interceptors.cc @@ -35,6 +35,7 @@ #include "sanitizer_common/sanitizer_tls_get_addr.h" #if SANITIZER_NETBSD +#define fstat __fstat50 #define gettimeofday __gettimeofday50 #define getrusage __getrusage50 #endif @@ -688,6 +689,19 @@ INTERCEPTOR(int, putenv, char *string) { return res; } +#if SANITIZER_NETBSD +INTERCEPTOR(int, fstat, int fd, void *buf) { + ENSURE_MSAN_INITED(); + int res = REAL(fstat)(fd, buf); + if (!res) + __msan_unpoison(buf, __sanitizer::struct_stat_sz); + return res; +} +#define MSAN_MAYBE_INTERCEPT_FSTAT INTERCEPT_FUNCTION(fstat) +#else +#define MSAN_MAYBE_INTERCEPT_FSTAT +#endif + #if !SANITIZER_FREEBSD && !SANITIZER_NETBSD INTERCEPTOR(int, __fxstat, int magic, int fd, void *buf) { ENSURE_MSAN_INITED(); @@ -1633,6 +1647,7 @@ void InitializeInterceptors() { INTERCEPT_FUNCTION(putenv); INTERCEPT_FUNCTION(gettimeofday); MSAN_MAYBE_INTERCEPT_FCVT; + MSAN_MAYBE_INTERCEPT_FSTAT; MSAN_MAYBE_INTERCEPT___FXSTAT; MSAN_INTERCEPT_FSTATAT; MSAN_MAYBE_INTERCEPT___FXSTAT64; diff --git a/compiler-rt/test/msan/fstat.cc b/compiler-rt/test/msan/fstat.cc new file mode 100644 index 00000000000..83f97054cea --- /dev/null +++ b/compiler-rt/test/msan/fstat.cc @@ -0,0 +1,15 @@ +// RUN: %clangxx_msan -O0 %s -o %t && %run %t + +#include <sys/stat.h> +#include <stdlib.h> + +int main(void) { + struct stat st; + if (fstat(0, &st)) + exit(1); + + if (S_ISBLK(st.st_mode)) + exit(0); + + return 0; +} |