From 9e7da0fb44b6d999700ba96743b16c1c112c2baa Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Thu, 24 Jul 2014 01:53:11 +0000 Subject: [PATCH] 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. llvm-svn: 213829 --- .../Process/gdb-remote/GDBRemoteRegisterContext.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp index 99e1a03..6d7eca1 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -233,11 +233,20 @@ GDBRemoteRegisterContext::ReadRegisterBytes (const RegisterInfo *reg_info, DataE 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::WriteRegisterBytes (const lldb_private::RegisterInfo * // 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(m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size)); -- 2.7.4