diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp index 3ea9e54a046cf..83e6cdd4a0094 100644 --- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp @@ -244,6 +244,18 @@ INTERCEPTOR(int, close, int filedes) { return REAL(close)(filedes); } +INTERCEPTOR(int, chdir, const char *path) { + __rtsan_notify_intercepted_call("chdir"); + return REAL(chdir)(path); +} + +INTERCEPTOR(int, fchdir, int fd) { + __rtsan_notify_intercepted_call("fchdir"); + return REAL(fchdir)(fd); +} + +// Streams + INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) { __rtsan_notify_intercepted_call("fopen"); return REAL(fopen)(path, mode); @@ -254,8 +266,6 @@ INTERCEPTOR(FILE *, freopen, const char *path, const char *mode, FILE *stream) { return REAL(freopen)(path, mode, stream); } -// Streams - #if SANITIZER_INTERCEPT_FOPEN64 INTERCEPTOR(FILE *, fopen64, const char *path, const char *mode) { __rtsan_notify_intercepted_call("fopen64"); @@ -1390,6 +1400,8 @@ void __rtsan::InitializeInterceptors() { INTERCEPT_FUNCTION(openat); RTSAN_MAYBE_INTERCEPT_OPENAT64; INTERCEPT_FUNCTION(close); + INTERCEPT_FUNCTION(chdir); + INTERCEPT_FUNCTION(fchdir); INTERCEPT_FUNCTION(fopen); RTSAN_MAYBE_INTERCEPT_FOPEN64; RTSAN_MAYBE_INTERCEPT_FREOPEN64; diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp index e3688157a842c..075f5974b7562 100644 --- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp @@ -445,6 +445,18 @@ TEST(TestRtsanInterceptors, CloseDiesWhenRealtime) { ExpectNonRealtimeSurvival(Func); } +TEST(TestRtsanInterceptors, ChdirDiesWhenRealtime) { + auto Func = []() { chdir("."); }; + ExpectRealtimeDeath(Func, "chdir"); + ExpectNonRealtimeSurvival(Func); +} + +TEST(TestRtsanInterceptors, FchdirDiesWhenRealtime) { + auto Func = []() { fchdir(0); }; + ExpectRealtimeDeath(Func, "fchdir"); + ExpectNonRealtimeSurvival(Func); +} + TEST_F(RtsanFileTest, FopenDiesWhenRealtime) { auto Func = [this]() { FILE *f = fopen(GetTemporaryFilePath(), "w");