Skip to content

Commit fa10047

Browse files
authored
[compiler-rt][rtsan] chdir/fchdir interception. (#125895)
1 parent a57bbff commit fa10047

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,18 @@ INTERCEPTOR(int, close, int filedes) {
244244
return REAL(close)(filedes);
245245
}
246246

247+
INTERCEPTOR(int, chdir, const char *path) {
248+
__rtsan_notify_intercepted_call("chdir");
249+
return REAL(chdir)(path);
250+
}
251+
252+
INTERCEPTOR(int, fchdir, int fd) {
253+
__rtsan_notify_intercepted_call("fchdir");
254+
return REAL(fchdir)(fd);
255+
}
256+
257+
// Streams
258+
247259
INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) {
248260
__rtsan_notify_intercepted_call("fopen");
249261
return REAL(fopen)(path, mode);
@@ -254,8 +266,6 @@ INTERCEPTOR(FILE *, freopen, const char *path, const char *mode, FILE *stream) {
254266
return REAL(freopen)(path, mode, stream);
255267
}
256268

257-
// Streams
258-
259269
#if SANITIZER_INTERCEPT_FOPEN64
260270
INTERCEPTOR(FILE *, fopen64, const char *path, const char *mode) {
261271
__rtsan_notify_intercepted_call("fopen64");
@@ -1390,6 +1400,8 @@ void __rtsan::InitializeInterceptors() {
13901400
INTERCEPT_FUNCTION(openat);
13911401
RTSAN_MAYBE_INTERCEPT_OPENAT64;
13921402
INTERCEPT_FUNCTION(close);
1403+
INTERCEPT_FUNCTION(chdir);
1404+
INTERCEPT_FUNCTION(fchdir);
13931405
INTERCEPT_FUNCTION(fopen);
13941406
RTSAN_MAYBE_INTERCEPT_FOPEN64;
13951407
RTSAN_MAYBE_INTERCEPT_FREOPEN64;

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,18 @@ TEST(TestRtsanInterceptors, CloseDiesWhenRealtime) {
445445
ExpectNonRealtimeSurvival(Func);
446446
}
447447

448+
TEST(TestRtsanInterceptors, ChdirDiesWhenRealtime) {
449+
auto Func = []() { chdir("."); };
450+
ExpectRealtimeDeath(Func, "chdir");
451+
ExpectNonRealtimeSurvival(Func);
452+
}
453+
454+
TEST(TestRtsanInterceptors, FchdirDiesWhenRealtime) {
455+
auto Func = []() { fchdir(0); };
456+
ExpectRealtimeDeath(Func, "fchdir");
457+
ExpectNonRealtimeSurvival(Func);
458+
}
459+
448460
TEST_F(RtsanFileTest, FopenDiesWhenRealtime) {
449461
auto Func = [this]() {
450462
FILE *f = fopen(GetTemporaryFilePath(), "w");

0 commit comments

Comments
 (0)