Check if null buffer handed to SBProcess::ReadMemory
authorJason Molenda <jason@molenda.com>
Tue, 7 Feb 2023 21:54:41 +0000 (13:54 -0800)
committerJason Molenda <jason@molenda.com>
Tue, 7 Feb 2023 22:16:04 +0000 (14:16 -0800)
commit62c747517cd9a0d57f198e0fd0984f71fe75240f
tree21565ac32ecabeb40c200b6b860323a0d5391eeb
parent32efff591abb159ca18d6c8c974d3ca45d444864
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
lldb/source/API/SBProcess.cpp
lldb/test/API/python_api/process/TestProcessAPI.py