[Lldb-commits] [lldb] r213829 - Add debug asserts / sanity checks to

Jason Molenda jmolenda at apple.com
Wed Jul 23 18:53:11 PDT 2014


Author: jmolenda
Date: Wed Jul 23 20:53:11 2014
New Revision: 213829

URL: http://llvm.org/viewvc/llvm-project?rev=213829&view=rev
Log:
Add debug asserts / sanity checks to
GDBRemoteRegisterContext::ReadRegisterBytes and
GDBRemoteRegisterContext::WriteRegisterBytes to ensure we don't try
to read/write off the end of the register buffer.  This should never
happen but we've had some target confusion in the past where it
did; adding the checks is prudent to avoid crashing here if it happens
again.

<rdar://problem/16450971> 
<rdar://problem/16458182>


Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp?rev=213829&r1=213828&r2=213829&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp Wed Jul 23 20:53:11 2014
@@ -233,11 +233,20 @@ GDBRemoteRegisterContext::ReadRegisterBy
 
     if (&data != &m_reg_data)
     {
+#if defined (LLDB_CONFIGURATION_DEBUG)
+        assert (m_reg_data.GetByteSize() >= reg_info->byte_offset + reg_info->byte_size);
+#endif  
+        // If our register context and our register info disagree, which should never happen, don't
+        // read past the end of the buffer.
+        if (m_reg_data.GetByteSize() < reg_info->byte_offset + reg_info->byte_size)
+            return false;
+
         // If we aren't extracting into our own buffer (which
         // only happens when this function is called from
         // ReadRegisterValue(uint32_t, Scalar&)) then
         // we transfer bytes from our buffer into the data
         // buffer that was passed in
+
         data.SetByteOrder (m_reg_data.GetByteOrder());
         data.SetData (m_reg_data, reg_info->byte_offset, reg_info->byte_size);
     }
@@ -323,6 +332,16 @@ GDBRemoteRegisterContext::WriteRegisterB
 //    if (gdb_comm.IsRunning())
 //        return false;
 
+
+#if defined (LLDB_CONFIGURATION_DEBUG)
+    assert (m_reg_data.GetByteSize() >= reg_info->byte_offset + reg_info->byte_size);
+#endif
+
+    // If our register context and our register info disagree, which should never happen, don't
+    // overwrite past the end of the buffer.
+    if (m_reg_data.GetByteSize() < reg_info->byte_offset + reg_info->byte_size)
+        return false;
+
     // Grab a pointer to where we are going to put this register
     uint8_t *dst = const_cast<uint8_t*>(m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size));
 





More information about the lldb-commits mailing list