forked from OSchip/llvm-project
[sanitizer] Move *stat to the common interceptors
Adds *stat to the common interceptors. Removes the now-duplicate *stat interceptor from msan/tsan/esan. This adds *stat to asan, which previously did not intercept it. Patch by Qin Zhao. llvm-svn: 269223
This commit is contained in:
parent
42369dbc01
commit
feb73c8566
|
@ -263,72 +263,6 @@ INTERCEPTOR(char *, strncpy, char *dst, char *src, uptr n) {
|
|||
return REAL(strncpy)(dst, src, n);
|
||||
}
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_FREEBSD
|
||||
INTERCEPTOR(int, __xstat64, int version, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, __xstat64, version, path, buf);
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
return REAL(__xstat64)(version, path, buf);
|
||||
}
|
||||
#define ESAN_MAYBE_INTERCEPT___XSTAT64 INTERCEPT_FUNCTION(__xstat64)
|
||||
#else
|
||||
#define ESAN_MAYBE_INTERCEPT___XSTAT64
|
||||
#endif
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_FREEBSD
|
||||
INTERCEPTOR(int, stat64, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, stat64, path, buf);
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
return REAL(stat64)(path, buf);
|
||||
}
|
||||
#define ESAN_MAYBE_INTERCEPT_STAT64 INTERCEPT_FUNCTION(stat64)
|
||||
#else
|
||||
#define ESAN_MAYBE_INTERCEPT_STAT64
|
||||
#endif
|
||||
|
||||
#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_ANDROID
|
||||
INTERCEPTOR(int, lstat, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, lstat, path, buf);
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
return REAL(lstat)(path, buf);
|
||||
}
|
||||
#define ESAN_INTERCEPT_LSTAT INTERCEPT_FUNCTION(lstat)
|
||||
#else
|
||||
INTERCEPTOR(int, __lxstat, int version, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, __lxstat, version, path, buf);
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
return REAL(__lxstat)(version, path, buf);
|
||||
}
|
||||
#define ESAN_INTERCEPT_LSTAT INTERCEPT_FUNCTION(__lxstat)
|
||||
#endif
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_FREEBSD
|
||||
INTERCEPTOR(int, __lxstat64, int version, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, __lxstat64, version, path, buf);
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
return REAL(__lxstat64)(version, path, buf);
|
||||
}
|
||||
#define ESAN_MAYBE_INTERCEPT___LXSTAT64 INTERCEPT_FUNCTION(__lxstat64)
|
||||
#else
|
||||
#define ESAN_MAYBE_INTERCEPT___LXSTAT64
|
||||
#endif
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_FREEBSD
|
||||
INTERCEPTOR(int, lstat64, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, lstat64, path, buf);
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
return REAL(lstat64)(path, buf);
|
||||
}
|
||||
#define ESAN_MAYBE_INTERCEPT_LSTAT64 INTERCEPT_FUNCTION(lstat64)
|
||||
#else
|
||||
#define ESAN_MAYBE_INTERCEPT_LSTAT64
|
||||
#endif
|
||||
|
||||
INTERCEPTOR(int, open, const char *name, int flags, int mode) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, open, name, flags, mode);
|
||||
|
@ -460,11 +394,6 @@ void initializeInterceptors() {
|
|||
INTERCEPT_FUNCTION(strcpy); // NOLINT
|
||||
INTERCEPT_FUNCTION(strncpy);
|
||||
|
||||
ESAN_MAYBE_INTERCEPT_STAT64;
|
||||
ESAN_MAYBE_INTERCEPT___XSTAT64;
|
||||
ESAN_INTERCEPT_LSTAT;
|
||||
ESAN_MAYBE_INTERCEPT_LSTAT64;
|
||||
ESAN_MAYBE_INTERCEPT___LXSTAT64;
|
||||
INTERCEPT_FUNCTION(open);
|
||||
ESAN_MAYBE_INTERCEPT_OPEN64;
|
||||
INTERCEPT_FUNCTION(creat);
|
||||
|
|
|
@ -742,45 +742,6 @@ INTERCEPTOR(int, __fxstatat64, int magic, int fd, char *pathname, void *buf,
|
|||
#define MSAN_MAYBE_INTERCEPT___FXSTATAT64
|
||||
#endif
|
||||
|
||||
#if !SANITIZER_FREEBSD
|
||||
INTERCEPTOR(int, __xstat64, int magic, char *path, void *buf) {
|
||||
ENSURE_MSAN_INITED();
|
||||
int res = REAL(__xstat64)(magic, path, buf);
|
||||
if (!res)
|
||||
__msan_unpoison(buf, __sanitizer::struct_stat64_sz);
|
||||
return res;
|
||||
}
|
||||
#define MSAN_MAYBE_INTERCEPT___XSTAT64 INTERCEPT_FUNCTION(__xstat64)
|
||||
#else
|
||||
#define MSAN_MAYBE_INTERCEPT___XSTAT64
|
||||
#endif
|
||||
|
||||
#if !SANITIZER_FREEBSD
|
||||
INTERCEPTOR(int, __lxstat, int magic, char *path, void *buf) {
|
||||
ENSURE_MSAN_INITED();
|
||||
int res = REAL(__lxstat)(magic, path, buf);
|
||||
if (!res)
|
||||
__msan_unpoison(buf, __sanitizer::struct_stat_sz);
|
||||
return res;
|
||||
}
|
||||
#define MSAN_MAYBE_INTERCEPT___LXSTAT INTERCEPT_FUNCTION(__lxstat)
|
||||
#else
|
||||
#define MSAN_MAYBE_INTERCEPT___LXSTAT
|
||||
#endif
|
||||
|
||||
#if !SANITIZER_FREEBSD
|
||||
INTERCEPTOR(int, __lxstat64, int magic, char *path, void *buf) {
|
||||
ENSURE_MSAN_INITED();
|
||||
int res = REAL(__lxstat64)(magic, path, buf);
|
||||
if (!res)
|
||||
__msan_unpoison(buf, __sanitizer::struct_stat64_sz);
|
||||
return res;
|
||||
}
|
||||
#define MSAN_MAYBE_INTERCEPT___LXSTAT64 INTERCEPT_FUNCTION(__lxstat64)
|
||||
#else
|
||||
#define MSAN_MAYBE_INTERCEPT___LXSTAT64
|
||||
#endif
|
||||
|
||||
INTERCEPTOR(int, pipe, int pipefd[2]) {
|
||||
if (msan_init_is_running)
|
||||
return REAL(pipe)(pipefd);
|
||||
|
@ -1590,11 +1551,8 @@ void InitializeInterceptors() {
|
|||
INTERCEPT_FUNCTION(fcvt);
|
||||
MSAN_MAYBE_INTERCEPT___FXSTAT;
|
||||
MSAN_INTERCEPT_FSTATAT;
|
||||
MSAN_MAYBE_INTERCEPT___LXSTAT;
|
||||
MSAN_MAYBE_INTERCEPT___FXSTAT64;
|
||||
MSAN_MAYBE_INTERCEPT___FXSTATAT64;
|
||||
MSAN_MAYBE_INTERCEPT___XSTAT64;
|
||||
MSAN_MAYBE_INTERCEPT___LXSTAT64;
|
||||
INTERCEPT_FUNCTION(pipe);
|
||||
INTERCEPT_FUNCTION(pipe2);
|
||||
INTERCEPT_FUNCTION(socketpair);
|
||||
|
|
|
@ -5561,6 +5561,54 @@ INTERCEPTOR(int, __xstat, int version, const char *path, void *buf) {
|
|||
#define INIT___XSTAT
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT___XSTAT64
|
||||
INTERCEPTOR(int, __xstat64, int version, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, __xstat64, version, path, buf);
|
||||
if (common_flags()->intercept_stat)
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
int res = REAL(__xstat64)(version, path, buf);
|
||||
if (!res)
|
||||
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat64_sz);
|
||||
return res;
|
||||
}
|
||||
#define INIT___XSTAT64 COMMON_INTERCEPT_FUNCTION(__xstat64)
|
||||
#else
|
||||
#define INIT___XSTAT64
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT___LXSTAT
|
||||
INTERCEPTOR(int, __lxstat, int version, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, __lxstat, version, path, buf);
|
||||
if (common_flags()->intercept_stat)
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
int res = REAL(__lxstat)(version, path, buf);
|
||||
if (!res)
|
||||
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat_sz);
|
||||
return res;
|
||||
}
|
||||
#define INIT___LXSTAT COMMON_INTERCEPT_FUNCTION(__lxstat)
|
||||
#else
|
||||
#define INIT___LXSTAT
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT___LXSTAT64
|
||||
INTERCEPTOR(int, __lxstat64, int version, const char *path, void *buf) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, __lxstat64, version, path, buf);
|
||||
if (common_flags()->intercept_stat)
|
||||
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
|
||||
int res = REAL(__lxstat64)(version, path, buf);
|
||||
if (!res)
|
||||
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat64_sz);
|
||||
return res;
|
||||
}
|
||||
#define INIT___LXSTAT64 COMMON_INTERCEPT_FUNCTION(__lxstat64)
|
||||
#else
|
||||
#define INIT___LXSTAT64
|
||||
#endif
|
||||
|
||||
// FIXME: add other *stat interceptor
|
||||
|
||||
static void InitializeCommonInterceptors() {
|
||||
|
@ -5750,5 +5798,8 @@ static void InitializeCommonInterceptors() {
|
|||
INIT_RECV_RECVFROM;
|
||||
INIT_STAT;
|
||||
INIT___XSTAT;
|
||||
INIT___XSTAT64;
|
||||
INIT___LXSTAT;
|
||||
INIT___LXSTAT64;
|
||||
// FIXME: add other *stat interceptors.
|
||||
}
|
||||
|
|
|
@ -299,4 +299,7 @@
|
|||
|
||||
#define SANITIZER_INTERCEPT_STAT (SI_FREEBSD || SI_MAC || SI_ANDROID)
|
||||
#define SANITIZER_INTERCEPT___XSTAT !SANITIZER_INTERCEPT_STAT && SI_NOT_WINDOWS
|
||||
#define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID
|
||||
#define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
|
||||
#define SANITIZER_INTERCEPT___LXSTAT64 SI_LINUX_NOT_ANDROID
|
||||
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
|
||||
|
|
|
@ -1350,73 +1350,6 @@ TSAN_INTERCEPTOR(int, pthread_once, void *o, void (*f)()) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
||||
TSAN_INTERCEPTOR(int, __xstat64, int version, const char *path, void *buf) {
|
||||
SCOPED_TSAN_INTERCEPTOR(__xstat64, version, path, buf);
|
||||
READ_STRING(thr, pc, path, 0);
|
||||
return REAL(__xstat64)(version, path, buf);
|
||||
}
|
||||
#define TSAN_MAYBE_INTERCEPT___XSTAT64 TSAN_INTERCEPT(__xstat64)
|
||||
#else
|
||||
#define TSAN_MAYBE_INTERCEPT___XSTAT64
|
||||
#endif
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
||||
TSAN_INTERCEPTOR(int, stat64, const char *path, void *buf) {
|
||||
SCOPED_TSAN_INTERCEPTOR(__xstat64, 0, path, buf);
|
||||
READ_STRING(thr, pc, path, 0);
|
||||
return REAL(__xstat64)(0, path, buf);
|
||||
}
|
||||
#define TSAN_MAYBE_INTERCEPT_STAT64 TSAN_INTERCEPT(stat64)
|
||||
#else
|
||||
#define TSAN_MAYBE_INTERCEPT_STAT64
|
||||
#endif
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
||||
TSAN_INTERCEPTOR(int, __lxstat, int version, const char *path, void *buf) {
|
||||
SCOPED_TSAN_INTERCEPTOR(__lxstat, version, path, buf);
|
||||
READ_STRING(thr, pc, path, 0);
|
||||
return REAL(__lxstat)(version, path, buf);
|
||||
}
|
||||
#define TSAN_MAYBE_INTERCEPT___LXSTAT TSAN_INTERCEPT(__lxstat)
|
||||
#else
|
||||
#define TSAN_MAYBE_INTERCEPT___LXSTAT
|
||||
#endif
|
||||
|
||||
TSAN_INTERCEPTOR(int, lstat, const char *path, void *buf) {
|
||||
#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_ANDROID
|
||||
SCOPED_TSAN_INTERCEPTOR(lstat, path, buf);
|
||||
READ_STRING(thr, pc, path, 0);
|
||||
return REAL(lstat)(path, buf);
|
||||
#else
|
||||
SCOPED_TSAN_INTERCEPTOR(__lxstat, 0, path, buf);
|
||||
READ_STRING(thr, pc, path, 0);
|
||||
return REAL(__lxstat)(0, path, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
||||
TSAN_INTERCEPTOR(int, __lxstat64, int version, const char *path, void *buf) {
|
||||
SCOPED_TSAN_INTERCEPTOR(__lxstat64, version, path, buf);
|
||||
READ_STRING(thr, pc, path, 0);
|
||||
return REAL(__lxstat64)(version, path, buf);
|
||||
}
|
||||
#define TSAN_MAYBE_INTERCEPT___LXSTAT64 TSAN_INTERCEPT(__lxstat64)
|
||||
#else
|
||||
#define TSAN_MAYBE_INTERCEPT___LXSTAT64
|
||||
#endif
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
||||
TSAN_INTERCEPTOR(int, lstat64, const char *path, void *buf) {
|
||||
SCOPED_TSAN_INTERCEPTOR(__lxstat64, 0, path, buf);
|
||||
READ_STRING(thr, pc, path, 0);
|
||||
return REAL(__lxstat64)(0, path, buf);
|
||||
}
|
||||
#define TSAN_MAYBE_INTERCEPT_LSTAT64 TSAN_INTERCEPT(lstat64)
|
||||
#else
|
||||
#define TSAN_MAYBE_INTERCEPT_LSTAT64
|
||||
#endif
|
||||
|
||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
||||
TSAN_INTERCEPTOR(int, __fxstat, int version, int fd, void *buf) {
|
||||
SCOPED_TSAN_INTERCEPTOR(__fxstat, version, fd, buf);
|
||||
|
@ -2595,12 +2528,6 @@ void InitializeInterceptors() {
|
|||
|
||||
TSAN_INTERCEPT(pthread_once);
|
||||
|
||||
TSAN_MAYBE_INTERCEPT_STAT64;
|
||||
TSAN_MAYBE_INTERCEPT___XSTAT64;
|
||||
TSAN_INTERCEPT(lstat);
|
||||
TSAN_MAYBE_INTERCEPT___LXSTAT;
|
||||
TSAN_MAYBE_INTERCEPT_LSTAT64;
|
||||
TSAN_MAYBE_INTERCEPT___LXSTAT64;
|
||||
TSAN_INTERCEPT(fstat);
|
||||
TSAN_MAYBE_INTERCEPT___FXSTAT;
|
||||
TSAN_MAYBE_INTERCEPT_FSTAT64;
|
||||
|
|
Loading…
Reference in New Issue