forked from OSchip/llvm-project
[Msan] Intercept stat() and fstatat() on FreeBSD
Differential Revision: http://reviews.llvm.org/D7051 llvm-svn: 226461
This commit is contained in:
parent
62975f55c8
commit
68f150f3d4
|
@ -703,7 +703,15 @@ INTERCEPTOR(int, __fxstat64, int magic, int fd, void *buf) {
|
|||
#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 @@ INTERCEPTOR(int, __fxstatat, int magic, int fd, char *pathname, void *buf,
|
|||
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 @@ INTERCEPTOR(int, __fxstatat64, int magic, int fd, char *pathname, void *buf,
|
|||
#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 @@ INTERCEPTOR(int, __xstat, int magic, char *path, void *buf) {
|
|||
__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 @@ void InitializeInterceptors() {
|
|||
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;
|
||||
|
|
|
@ -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, stat) {
|
|||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue