Skip to content

Commit 0cd70b7

Browse files
committed
[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 f4214e1 ("[sanitizer] Skip test on Android where chmod is not working"), since we shouldn't need to exclude Android anymore.
1 parent 3b7a7f4 commit 0cd70b7

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_bad_report_path_test.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_path_test.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test __sanitizer_set_report_path and __sanitizer_get_report_path:
22
// RUN: %clangxx -O2 %s -o %t
3-
// RUN: %run %t | FileCheck %s
3+
// RUN: not %run %t 2>&1 | FileCheck %s
44

55
#include <assert.h>
66
#include <sanitizer/common_interface_defs.h>
@@ -15,6 +15,14 @@ int main(int argc, char **argv) {
1515
__sanitizer_set_report_path(buff);
1616
assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0);
1717
printf("Path %s\n", __sanitizer_get_report_path());
18+
fflush(stdout);
19+
20+
// Try setting again with an invalid/inaccessible directory.
21+
sprintf(buff, "%s/report", argv[0]);
22+
__sanitizer_set_report_path(buff);
23+
printf("Path %s\n", __sanitizer_get_report_path());
1824
}
1925

2026
// CHECK: Path {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp.report_path/report.
27+
// CHECK: ERROR: Can't create directory: {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp
28+
// CHECK-NOT: Path {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp

0 commit comments

Comments
 (0)