Page MenuHomePhabricator

Fix potential UB when target_file directory is null
ClosedPublic

Authored by sgraenitz on Feb 8 2019, 10:56 AM.

Details

Summary

As seen in a crash report, the C-string returned for the directory component of target_file can null. It should not be assigned to std::string directly as this is undefined behavior.

Diff Detail

Repository
rLLDB LLDB

Event Timeline

sgraenitz created this revision.Feb 8 2019, 10:56 AM
sgraenitz updated this revision to Diff 186002.Feb 8 2019, 11:00 AM

Remove useless newline

Might be clearer to do:

if (target_file.GetDirectory().IsEmpty()) {
    error...
}
std::string directory = ...

Avoids the extra variable and also adds the check for "", which I don't think we want to add to sys.path either.

sgraenitz updated this revision to Diff 186224.Feb 11 2019, 3:43 AM

Polish && error out also on empty string

jingham accepted this revision.Feb 14 2019, 10:51 AM

That code seems amazingly good to me ;-)

This revision is now accepted and ready to land.Feb 14 2019, 10:51 AM
Closed by commit rLLDB354145: Fix potential UB when target_file directory is null (authored by stefan.graenitz, committed by ). · Explain WhyFeb 15 2019, 8:42 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 15 2019, 8:42 AM