-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[compiler-rt][rtsan] fopencookie support. #120864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/120864.diff 2 Files Affected:
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index 4e51f464b57304..072923ab35ae0d 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -297,6 +297,12 @@ INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
return REAL(fdopen)(fd, mode);
}
+INTERCEPTOR(FILE *, fopencookie, void *cookie, const char *mode,
+ cookie_io_functions_t funcs) {
+ __rtsan_notify_intercepted_call("fopencookie");
+ return REAL(fopencookie)(cookie, mode, funcs);
+}
+
#if SANITIZER_INTERCEPT_OPEN_MEMSTREAM
INTERCEPTOR(FILE *, open_memstream, char **buf, size_t *size) {
__rtsan_notify_intercepted_call("open_memstream");
@@ -972,6 +978,7 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(fputs);
INTERCEPT_FUNCTION(fdopen);
INTERCEPT_FUNCTION(freopen);
+ INTERCEPT_FUNCTION(fopencookie);
RTSAN_MAYBE_INTERCEPT_OPEN_MEMSTREAM;
RTSAN_MAYBE_INTERCEPT_FMEMOPEN;
INTERCEPT_FUNCTION(lseek);
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 b052dd859dcdf6..8fa396fb415ac5 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -299,7 +299,7 @@ TEST_F(RtsanFileTest, FcntlFlockDiesWhenRealtime) {
ASSERT_THAT(fd, Ne(-1));
auto Func = [fd]() {
- struct flock lock {};
+ struct flock lock{};
lock.l_type = F_RDLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
@@ -353,6 +353,29 @@ TEST_F(RtsanFileTest, FopenDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+TEST_F(RtsanFileTest, FopenCookieDieWhenRealtime) {
+ FILE *f = fopen(GetTemporaryFilePath(), "w");
+ EXPECT_THAT(f, Ne(nullptr));
+ struct fholder {
+ FILE *fp;
+ size_t read;
+ } fh = {f, 0};
+ auto CookieRead = [this](void *cookie, char *buf, size_t size) {
+ fholder *p = reinterpret_cast<fholder *>(cookie);
+ p->read = fread(static_cast<void *>(buf), 1, size, p->fp);
+ EXPECT_NE(0, p->read);
+ };
+ cookie_io_functions_t funcs = {(cookie_read_function_t *)&CookieRead, nullptr,
+ nullptr, nullptr};
+ auto Func = [&fh, &funcs]() {
+ FILE *f = fopencookie(&fh, "w", funcs);
+ EXPECT_THAT(f, Ne(nullptr));
+ };
+
+ ExpectRealtimeDeath(Func, "fopencookie");
+ ExpectNonRealtimeSurvival(Func);
+}
+
#if SANITIZER_INTERCEPT_OPEN_MEMSTREAM
TEST_F(RtsanFileTest, OpenMemstreamDiesWhenRealtime) {
char *buffer;
@@ -453,7 +476,7 @@ TEST(TestRtsanInterceptors, IoctlBehavesWithOutputPointer) {
GTEST_SKIP();
}
- struct ifreq ifr {};
+ struct ifreq ifr{};
strncpy(ifr.ifr_name, ifaddr->ifa_name, IFNAMSIZ - 1);
int retval = ioctl(sock, SIOCGIFADDR, &ifr);
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
0b85ffe to
9c46d95
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/13915 Here is the relevant piece of the build log for the reference |
|
This is just heads up that we started seeing this failure on our side after this patch: |
This reverts commit 4b57783.
Reverts #120864 because it broke building compiler-rt on Mac. https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-mac-arm64/b8726812736235038609/overview
|
Oh right macos dos not support it I see. Seems easy I just forgot to guard it with SANITIZER_INTERCEPT_FOPENCOOKIE. |
Reverts llvm/llvm-project#120864 because it broke building compiler-rt on Mac. https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-mac-arm64/b8726812736235038609/overview
No description provided.