summaryrefslogtreecommitdiff
path: root/lib/msan
diff options
context:
space:
mode:
authorKamil Rytarowski <n54@gmx.com>2018-01-03 22:28:39 +0000
committerKamil Rytarowski <n54@gmx.com>2018-01-03 22:28:39 +0000
commit127df3a5936479c254feb916ed97980c0a4f8931 (patch)
treea9ac463654912319db48c15361e0447d65ed37fb /lib/msan
parent3e3b3f00625ddb8dd56f1ee362855574071e9258 (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@321765 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/msan')
-rw-r--r--lib/msan/msan_interceptors.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc
index a7fe09b25..02b41efda 100644
--- a/lib/msan/msan_interceptors.cc
+++ b/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;