diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -802,8 +802,13 @@ 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()); diff --git a/lldb/test/API/python_api/process/TestProcessAPI.py b/lldb/test/API/python_api/process/TestProcessAPI.py --- a/lldb/test/API/python_api/process/TestProcessAPI.py +++ b/lldb/test/API/python_api/process/TestProcessAPI.py @@ -72,6 +72,20 @@ 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)