This is an archive of the discontinued LLVM Phabricator instance.

[Sanitizer] Use CreateDirectoryA for report dirs
ClosedPublic

Authored by tunz on Nov 29 2021, 5:28 PM.

Details

Summary

Using _mkdir of CRT in Asan Init leads to launch failure and hanging in Windows.

You can trigger it by calling:

set ASAN_OPTIONS=log_path=a/a/a
.\asan_program.exe

And their crash dump shows the following stack trace:

_guard_dispatch_icall_nop()
__acrt_get_utf8_acp_compatibility_codepage()
_mkdir(const char * path)

I guess there could be a cfg guard in CRT, which may lead to calling uninitialized cfg guard function address. Also, _mkdir supports UTF-8 encoding of the path and calls _wmkdir, but that's not necessary for this case since other file apis in sanitizer_win.cpp assumes only ANSI code case, so it makes sense to use CreateDirectoryA matching other file api calls in the same file.

Diff Detail

Event Timeline

tunz requested review of this revision.Nov 29 2021, 5:28 PM
tunz created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 29 2021, 5:28 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
tunz updated this revision to Diff 390532.Nov 29 2021, 5:31 PM

Set nullptr to the second arg.

tunz updated this revision to Diff 390535.Nov 29 2021, 5:44 PM

fileapi.h is unnecessary

tunz edited the summary of this revision. (Show Details)Nov 29 2021, 7:02 PM
tunz added reviewers: vitalybuka, tejohnson.
tejohnson accepted this revision.Nov 30 2021, 10:56 AM

I see CreateDirectoryA is also used in the Windows fuzzer support.

lgtm

This revision is now accepted and ready to land.Nov 30 2021, 10:56 AM
tunz added a comment.Nov 30 2021, 11:00 AM

Thanks for the review. Could you land it on behalf of me? I don't have commit access.

tunz added a comment.Dec 1 2021, 3:17 PM

Kindly ping. Can you commit this to main branch?

Kindly ping. Can you commit this to main branch?

I'll commit this today.

This revision was landed with ongoing or failed builds.Dec 3 2021, 12:34 PM
This revision was automatically updated to reflect the committed changes.