diff options
| author | Jason Molenda <jason@molenda.com> | 2023-02-07 13:54:41 -0800 |
|---|---|---|
| committer | Jason Molenda <jason@molenda.com> | 2023-02-07 14:16:04 -0800 |
| commit | 62c747517cd9a0d57f198e0fd0984f71fe75240f (patch) | |
| tree | 21565ac32ecabeb40c200b6b860323a0d5391eeb /lldb/test/API/python_api/process/TestProcessAPI.py | |
| parent | 32efff591abb159ca18d6c8c974d3ca45d444864 (diff) | |
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
Diffstat (limited to 'lldb/test/API/python_api/process/TestProcessAPI.py')
| -rw-r--r-- | lldb/test/API/python_api/process/TestProcessAPI.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/process/TestProcessAPI.py b/lldb/test/API/python_api/process/TestProcessAPI.py index cf05335b2384..36291fcc66b8 100644 --- a/lldb/test/API/python_api/process/TestProcessAPI.py +++ b/lldb/test/API/python_api/process/TestProcessAPI.py @@ -72,6 +72,20 @@ class ProcessAPITestCase(TestBase): exe=False, startstr=b'x') + # Try to read an impossibly large amount of memory; swig + # will try to malloc it and fail, we should get an error + # result. + error = lldb.SBError() + content = process.ReadMemory( + val.AddressOf().GetValueAsUnsigned(), + 0xffffffffffffffe8, error) + if error.Success(): + self.assertFalse(error.Success(), "SBProcessReadMemory claims to have " + "successfully read 0xffffffffffffffe8 bytes") + if self.TraceOn(): + print("Tried to read 0xffffffffffffffe8 bytes, got error message: ", + error.GetCString()) + # Read (char *)my_char_ptr. val = frame.FindValue("my_char_ptr", lldb.eValueTypeVariableGlobal) self.DebugSBValue(val) |
