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 @@ -804,6 +804,12 @@ size_t bytes_read = 0; + if (!dst) { + sb_error.SetErrorStringWithFormat( + "no buffer provided to read %zu bytes into", dst_len); + return 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 @@ -60,6 +60,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.fail("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)