diff options
author | Greg Clayton <gclayton@apple.com> | 2013-07-24 18:17:35 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2013-07-24 18:17:35 +0000 |
commit | 772a66793b0eb14b1bc6c4255b9b33610df8a488 (patch) | |
tree | 9c91cd1b2fe8015c1cd12362e5ec236601fd54c9 | |
parent | 14d0ef484e29c77b879c6b039e921d10020ef10f (diff) | |
download | lldb-772a66793b0eb14b1bc6c4255b9b33610df8a488.tar.gz |
<rdar://problem/14521548>
Fixed a crasher where if you accidentally specify a size that is too large when reading memory, LLDB would crash.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@187060 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | source/Commands/CommandObjectMemory.cpp | 13 | ||||
-rw-r--r-- | source/Core/DataBufferHeap.cpp | 4 |
2 files changed, 16 insertions, 1 deletions
diff --git a/source/Commands/CommandObjectMemory.cpp b/source/Commands/CommandObjectMemory.cpp index eea0cf500..4725a4da6 100644 --- a/source/Commands/CommandObjectMemory.cpp +++ b/source/Commands/CommandObjectMemory.cpp @@ -680,6 +680,13 @@ protected: else if (m_format_options.GetFormatValue().GetCurrentValue() != eFormatCString) { data_sp.reset (new DataBufferHeap (total_byte_size, '\0')); + if (data_sp->GetBytes() == NULL) + { + result.AppendErrorWithFormat ("can't allocate 0x%zx bytes for the memory read buffer, specify a smaller size to read", total_byte_size); + result.SetStatus(eReturnStatusFailed); + return false; + } + Address address(addr, NULL); bytes_read = target->ReadMemory(address, false, data_sp->GetBytes (), data_sp->GetByteSize(), error); if (bytes_read == 0) @@ -710,6 +717,12 @@ protected: if (!m_format_options.GetCountValue().OptionWasSet()) item_count = 1; data_sp.reset (new DataBufferHeap ((item_byte_size+1) * item_count, '\0')); // account for NULLs as necessary + if (data_sp->GetBytes() == NULL) + { + result.AppendErrorWithFormat ("can't allocate 0x%" PRIx64 " bytes for the memory read buffer, specify a smaller size to read", (uint64_t)((item_byte_size+1) * item_count)); + result.SetStatus(eReturnStatusFailed); + return false; + } uint8_t *data_ptr = data_sp->GetBytes(); auto data_addr = addr; auto count = item_count; diff --git a/source/Core/DataBufferHeap.cpp b/source/Core/DataBufferHeap.cpp index 74893767d..2c8a865b9 100644 --- a/source/Core/DataBufferHeap.cpp +++ b/source/Core/DataBufferHeap.cpp @@ -24,8 +24,10 @@ DataBufferHeap::DataBufferHeap () : // with "ch". //---------------------------------------------------------------------- DataBufferHeap::DataBufferHeap (lldb::offset_t n, uint8_t ch) : - m_data(n, ch) + m_data() { + if (n < m_data.max_size()) + m_data.assign (n, ch); } //---------------------------------------------------------------------- |