This is an archive of the discontinued LLVM Phabricator instance.

Add a bit of error checking to SBProcess::ReadMemory to check if a nullptr destination buffer was provided, return error
ClosedPublic

Authored by jasonmolenda on Jan 31 2023, 1:39 PM.

Details

Summary

I helped a developer using SB API yesterday who had a bug and tried to read 0xffffffffffffffe8 with SBProcess::ReadMemory. swig would try to malloc a buffer for that, which would fail but was not checked, and hand the nullptr to ReadMemory. lldb would continue on until it tried to copy bytes into the nullptr and crash.

Fixing the script was obvious, but having lldb crash out from under the script made it a little harder to debug. I think we should check for a null buffer at the SBProcess API point and return an error there.

Added a quick test to the ProcessAPI test. This call will cause a huge malloc which should safely fail on every platform I think? We may need to revise if this ends up crashing lldb on some target I guess.

Diff Detail

Event Timeline

jasonmolenda created this revision.Jan 31 2023, 1:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2023, 1:39 PM
jasonmolenda requested review of this revision.Jan 31 2023, 1:39 PM
JDevlieghere accepted this revision.Feb 6 2023, 3:02 PM

LGTM modulo inline comments

lldb/source/API/SBProcess.cpp
807–811

Nit: this isn't using bytes_read so I'd move the new code above it.

lldb/test/API/python_api/process/TestProcessAPI.py
82–84

self.assertFalse(error.Success(), "SBProcessReadMemory claims to have successfully read 0xffffffffffffffe8 bytes")

This revision is now accepted and ready to land.Feb 6 2023, 3:02 PM
mib accepted this revision.Feb 6 2023, 3:32 PM

LGTM with @JDevlieghere comments.

lldb/source/API/SBProcess.cpp
807–811

+1

Update patch for Jonas' suggestions.

This revision was automatically updated to reflect the committed changes.