[PATCH] D41637: Add MSan interceptor for fstat(2)
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 3 14:29:47 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT321765: Add MSan interceptor for fstat(2) (authored by kamil, committed by ).
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D41637
Files:
lib/msan/msan_interceptors.cc
test/msan/fstat.cc
Index: lib/msan/msan_interceptors.cc
===================================================================
--- lib/msan/msan_interceptors.cc
+++ 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 @@
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 @@
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;
Index: test/msan/fstat.cc
===================================================================
--- test/msan/fstat.cc
+++ 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;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41637.128566.patch
Type: text/x-patch
Size: 1510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180103/ea5db4fa/attachment.bin>
More information about the llvm-commits
mailing list