Page MenuHomePhabricator

Fix potential UB when target_file directory is null
ClosedPublic

Authored by sgraenitz on Fri, Feb 8, 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.Fri, Feb 8, 10:56 AM
sgraenitz updated this revision to Diff 186002.Fri, Feb 8, 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.Mon, Feb 11, 3:43 AM

Polish && error out also on empty string

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

That code seems amazingly good to me ;-)

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