summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2015-01-22 00:41:05 +0000
committerJason Molenda <jmolenda@apple.com>2015-01-22 00:41:05 +0000
commit03176d781f32d265cf3333af6abb22577c160f12 (patch)
tree439d295980578a91277eadb5b43c4c576ddb783a
parentd50c398c69df970e393566bdc2dd4e5100b78cda (diff)
downloadbcm5719-llvm-03176d781f32d265cf3333af6abb22577c160f12.tar.gz
bcm5719-llvm-03176d781f32d265cf3333af6abb22577c160f12.zip
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> llvm-svn: 226753
-rw-r--r--lldb/source/Host/common/File.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index c3c77835ce8..8568d8f1041 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -742,8 +742,9 @@ File::Read (size_t &num_bytes, off_t &offset, bool null_terminate, DataBufferSP
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 &offset, bool null_terminate, DataBufferSP
{
// 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;
}
OpenPOWER on IntegriCloud