Skip to content

Commit

Permalink
[sanitizer] Fix running sanitizer_bad_report_path_test on Linux as ro…
Browse files Browse the repository at this point in the history
…ot (llvm#97732)

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.
  • Loading branch information
iii-i authored and Harini0924 committed Jul 22, 2024
1 parent 46cd30c commit 7b358d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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

0 comments on commit 7b358d0

Please sign in to comment.