[Lldb-commits] [lldb] r187060 - <rdar://problem/14521548>

Greg Clayton gclayton at apple.com
Wed Jul 24 11:17:36 PDT 2013


Author: gclayton
Date: Wed Jul 24 13:17:35 2013
New Revision: 187060

URL: http://llvm.org/viewvc/llvm-project?rev=187060&view=rev
Log:
<rdar://problem/14521548>

Fixed a crasher where if you accidentally specify a size that is too large when reading memory, LLDB would crash.


Modified:
    lldb/trunk/source/Commands/CommandObjectMemory.cpp
    lldb/trunk/source/Core/DataBufferHeap.cpp

Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=187060&r1=187059&r2=187060&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Wed Jul 24 13:17:35 2013
@@ -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;

Modified: lldb/trunk/source/Core/DataBufferHeap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataBufferHeap.cpp?rev=187060&r1=187059&r2=187060&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataBufferHeap.cpp (original)
+++ lldb/trunk/source/Core/DataBufferHeap.cpp Wed Jul 24 13:17:35 2013
@@ -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);
 }
 
 //----------------------------------------------------------------------





More information about the lldb-commits mailing list