This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Check if directory exists before trying to create
ClosedPublic

Authored by tejohnson on Feb 10 2022, 3:47 PM.

Details

Summary

Add a DirExists mechanism, modeled after FileExists. Use it to guard
creation of the report path directory.

This should avoid failures running the sanitizer in a sandbox where the
file creation attempt causes hard failures, even for an existing
directory. Problem reported on D109794 for ChromeOS in sandbox
(https://issuetracker.google.com/209296420).

Diff Detail

Event Timeline

tejohnson requested review of this revision.Feb 10 2022, 3:47 PM
tejohnson created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2022, 3:47 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka accepted this revision.Feb 10 2022, 7:33 PM

it would be nice to have unittests:
TEST(SanitizerCommon, FileExists)
TEST(SanitizerCommon, DirExists)
TEST(SanitizerCommon, RecursiveCreateParentDirs)

compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
87–93
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
502–513

please clang-format

compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
93

hm looks like existing code is wrong

This revision is now accepted and ready to land.Feb 10 2022, 7:33 PM

Address comments

tejohnson marked 2 inline comments as done.Feb 11 2022, 11:57 AM

it would be nice to have unittests:
TEST(SanitizerCommon, FileExists)
TEST(SanitizerCommon, DirExists)
TEST(SanitizerCommon, RecursiveCreateParentDirs)

With D109794 I added TEST(SanitizerCommon, ReportFile) which does test RecursiveCreateParentDirs. Since RecursiveCreateParentDirs is a static function I can't call it directly from the unit tests.

I've added the FileExists and DirExists unit tests, however.

compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
93

Yeah that's what I thought too. I didn't want to change that part of the existing behavior, however, since it doesn't seem to be causing an issue.