[compiler-rt] [sanitizer] Misc error message improvements (PR #97732)
Ilya Leoshkevich via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 14 09:53:35 PDT 2024
https://github.com/iii-i updated https://github.com/llvm/llvm-project/pull/97732
>From 0cd70b73b2281dbd4b02bea21ddb26e3ed039e31 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii at linux.ibm.com>
Date: Fri, 12 Jul 2024 12:04:16 +0200
Subject: [PATCH] [sanitizer] Fix running sanitizer_bad_report_path_test on
Linux as root
Running tests as root is not the greatest idea, however, there is one
valid use case - running them in a container in order to verify LLVM on
different distros. There is no reason to configure unprivileged users
in a container, so one works as root.
sanitizer_bad_report_path_test assumes that creating a file in a
non-writable directory would fail, which is not the always case. For
example, when we are on Linux and CAP_DAC_OVERRIDE, which root has, is
in effect. Therefore, one solution is to drop it. However, that would
be Linux-specific.
Instead, use argv[0] as if it were a directory. mkdir() on top of a
file should be prohibited by all supported Posix operating systems.
Combine this with a partial revert of commit f4214e1469ad ("[sanitizer]
Skip test on Android where chmod is not working"), since we shouldn't
need to exclude Android anymore.
---
.../Posix/sanitizer_bad_report_path_test.cpp | 27 -------------------
.../Posix/sanitizer_set_report_path_test.cpp | 10 ++++++-
2 files changed, 9 insertions(+), 28 deletions(-)
delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_bad_report_path_test.cpp
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_bad_report_path_test.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_bad_report_path_test.cpp
deleted file mode 100644
index fd4abf448b09d..0000000000000
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_bad_report_path_test.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-// Test __sanitizer_set_report_path and __sanitizer_get_report_path with an
-// unwritable directory.
-// RUN: rm -rf %t.report_path && mkdir -p %t.report_path
-// RUN: chmod u-w %t.report_path || true
-// RUN: %clangxx -O2 %s -o %t
-// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=FAIL
-
-// The chmod is not working on the android bot for some reason.
-// UNSUPPORTED: android
-
-#include <assert.h>
-#include <sanitizer/common_interface_defs.h>
-#include <stdio.h>
-#include <string.h>
-
-volatile int *null = 0;
-
-int main(int argc, char **argv) {
- char buff[1000];
- sprintf(buff, "%s.report_path/report", argv[0]);
- __sanitizer_set_report_path(buff);
- assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0);
- printf("Path %s\n", __sanitizer_get_report_path());
-}
-
-// FAIL: ERROR: Can't open file: {{.*}}Posix/Output/sanitizer_bad_report_path_test.cpp.tmp.report_path/report.
-// FAIL-NOT: Path {{.*}}Posix/Output/sanitizer_bad_report_path_test.cpp.tmp.report_path/report.
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_path_test.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_path_test.cpp
index 17cee722749d6..286eafc315baf 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_path_test.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_path_test.cpp
@@ -1,6 +1,6 @@
// Test __sanitizer_set_report_path and __sanitizer_get_report_path:
// RUN: %clangxx -O2 %s -o %t
-// RUN: %run %t | FileCheck %s
+// RUN: not %run %t 2>&1 | FileCheck %s
#include <assert.h>
#include <sanitizer/common_interface_defs.h>
@@ -15,6 +15,14 @@ int main(int argc, char **argv) {
__sanitizer_set_report_path(buff);
assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0);
printf("Path %s\n", __sanitizer_get_report_path());
+ fflush(stdout);
+
+ // Try setting again with an invalid/inaccessible directory.
+ sprintf(buff, "%s/report", argv[0]);
+ __sanitizer_set_report_path(buff);
+ printf("Path %s\n", __sanitizer_get_report_path());
}
// CHECK: Path {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp.report_path/report.
+// CHECK: ERROR: Can't create directory: {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp
+// CHECK-NOT: Path {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp
More information about the llvm-commits
mailing list