[Lldb-commits] [lldb] r226753 - File::Read(), when asked to read the contents of a file into a heap

Jason Molenda jmolenda at apple.com
Wed Jan 21 16:41:06 PST 2015


Author: jmolenda
Date: Wed Jan 21 18:41:05 2015
New Revision: 226753

URL: http://llvm.org/viewvc/llvm-project?rev=226753&view=rev
Log:
File::Read(), when asked to read the contents of a file into a heap
buffer and to add a nul terminator byte, was incorrectly resizing
its buffer so the nul terminator was not included.

Problem found by clang ASAN instrumentation when using an
expression prefix file which was read via this mechanism.

<rdar://problem/19556459> 

Modified:
    lldb/trunk/source/Host/common/File.cpp

Modified: lldb/trunk/source/Host/common/File.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=226753&r1=226752&r2=226753&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/File.cpp (original)
+++ lldb/trunk/source/Host/common/File.cpp Wed Jan 21 18:41:05 2015
@@ -742,8 +742,9 @@ File::Read (size_t &num_bytes, off_t &of
                     if (num_bytes > bytes_left)
                         num_bytes = bytes_left;
                         
+                    size_t num_bytes_plus_nul_char = num_bytes + (null_terminate ? 1 : 0);
                     std::unique_ptr<DataBufferHeap> data_heap_ap;
-                    data_heap_ap.reset(new DataBufferHeap(num_bytes + (null_terminate ? 1 : 0), '\0'));
+                    data_heap_ap.reset(new DataBufferHeap(num_bytes_plus_nul_char, '\0'));
                         
                     if (data_heap_ap.get())
                     {
@@ -752,8 +753,8 @@ File::Read (size_t &num_bytes, off_t &of
                         {
                             // Make sure we read exactly what we asked for and if we got
                             // less, adjust the array
-                            if (num_bytes < data_heap_ap->GetByteSize())
-                                data_heap_ap->SetByteSize(num_bytes);
+                            if (num_bytes_plus_nul_char < data_heap_ap->GetByteSize())
+                                data_heap_ap->SetByteSize(num_bytes_plus_nul_char);
                             data_buffer_sp.reset(data_heap_ap.release());
                             return error;
                         }





More information about the lldb-commits mailing list