From c63dddd8007bbdf58ddfc649e74c65aa3bf7254d Mon Sep 17 00:00:00 2001 From: Daniel Malea Date: Fri, 14 Dec 2012 21:07:07 +0000 Subject: Avoid possible overflow when reading inferior memory (and logging is enabled) Patch by Matt Kopec! llvm-svn: 170242 --- lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp') diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp index 483834045cc..25794e80737 100644 --- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp +++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp @@ -200,8 +200,6 @@ DoReadMemory(lldb::pid_t pid, remainder = remainder > word_size ? word_size : remainder; // Copy the data into our buffer - if (log) - memset(dst, 0, sizeof(unsigned char)); for (unsigned i = 0; i < remainder; ++i) dst[i] = ((data >> i*8) & 0xFF); @@ -209,8 +207,14 @@ DoReadMemory(lldb::pid_t pid, (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_LONG) || (log->GetMask().Test(POSIX_LOG_MEMORY_DATA_SHORT) && size <= POSIX_LOG_MEMORY_SHORT_BYTES))) - log->Printf ("ProcessMonitor::%s() [%p]:0x%lx (0x%lx)", __FUNCTION__, - (void*)vm_addr, *(unsigned long*)dst, (unsigned long)data); + { + uintptr_t print_dst = 0; + // Format bytes from data by moving into print_dst for log output + for (unsigned i = 0; i < remainder; ++i) + print_dst |= (((data >> i*8) & 0xFF) << i*8); + log->Printf ("ProcessMonitor::%s() [%p]:0x%lx (0x%lx)", __FUNCTION__, + (void*)vm_addr, print_dst, (unsigned long)data); + } vm_addr += word_size; dst += word_size; -- cgit v1.2.3