Check if null buffer handed to SBProcess::ReadMemory

Add a check for a null destination buffer in SBProcess::ReadMemory,
and return an error if that happens.  If a Python SB API script
tries to allocate a huge amount of memory, the malloc done by the
intermediate layers will fail and will hand a null pointer to
ReadMemory.  lldb will eventually crash trying to write in to that
buffer.

Also add a test that tries to allocate an impossibly large amount
of memory, and hopefully should result in a failed malloc and hitting
this error codepath.

Differential Revision: https://reviews.llvm.org/D143012
rdar://104846609
This commit is contained in:
Jason Molenda
2023-02-07 13:54:41 -08:00
parent 32efff591a
commit 62c747517c
2 changed files with 20 additions and 1 deletions

View File

@@ -802,8 +802,13 @@ size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len,
SBError &sb_error) {
LLDB_INSTRUMENT_VA(this, addr, dst, dst_len, sb_error);
size_t bytes_read = 0;
if (!dst) {
sb_error.SetErrorStringWithFormat(
"no buffer provided to read %zu bytes into", dst_len);
return 0;
}
size_t bytes_read = 0;
ProcessSP process_sp(GetSP());