<rdar://problem/10652336>
Fixed a crasher when trying to load an expression prefix file:
% touch /tmp/carp.txt
% xcrun lldb
(lldb) settings set target.expr-prefix /tmp/carp.txt
Segmentation fault
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@147646 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/lldb/Host/FileSpec.h b/include/lldb/Host/FileSpec.h
index b1d2525..3ff405e 100644
--- a/include/lldb/Host/FileSpec.h
+++ b/include/lldb/Host/FileSpec.h
@@ -462,10 +462,10 @@
/// pointer must be checked prior to using it.
//------------------------------------------------------------------
lldb::DataBufferSP
- ReadFileContents (off_t offset = 0, size_t length = SIZE_MAX) const;
+ ReadFileContents (off_t offset = 0, size_t length = SIZE_MAX, Error *error_ptr = NULL) const;
size_t
- ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const;
+ ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const;
//------------------------------------------------------------------
/// Change the file specificed with a new path.
diff --git a/source/Core/Section.cpp b/source/Core/Section.cpp
index b8b9ddf..09394b2 100644
--- a/source/Core/Section.cpp
+++ b/source/Core/Section.cpp
@@ -339,7 +339,7 @@
if (section_offset < file_size)
{
off_t section_file_offset = objfile->GetOffset() + GetFileOffset() + section_offset;
- bytes_read = file.ReadFileContents (section_file_offset, dst, dst_len);
+ bytes_read = file.ReadFileContents (section_file_offset, dst, dst_len, NULL);
if (bytes_read >= dst_len)
return bytes_read;
bytes_left -= bytes_read;
diff --git a/source/Host/common/FileSpec.cpp b/source/Host/common/FileSpec.cpp
index 1f0942d..f769d2e 100644
--- a/source/Host/common/FileSpec.cpp
+++ b/source/Host/common/FileSpec.cpp
@@ -771,13 +771,13 @@
size_t
-FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const
+FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const
{
+ Error error;
size_t bytes_read = 0;
char resolved_path[PATH_MAX];
if (GetPath(resolved_path, sizeof(resolved_path)))
{
- Error error;
File file;
error = file.Open(resolved_path, File::eOpenOptionRead);
if (error.Success())
@@ -787,6 +787,12 @@
error = file.Read(dst, bytes_read, file_offset_after_seek);
}
}
+ else
+ {
+ error.SetErrorString("invalid file specification");
+ }
+ if (error_ptr)
+ *error_ptr = error;
return bytes_read;
}
@@ -802,18 +808,24 @@
// verified using the DataBuffer::GetByteSize() function.
//------------------------------------------------------------------
DataBufferSP
-FileSpec::ReadFileContents (off_t file_offset, size_t file_size) const
+FileSpec::ReadFileContents (off_t file_offset, size_t file_size, Error *error_ptr) const
{
+ Error error;
DataBufferSP data_sp;
char resolved_path[PATH_MAX];
if (GetPath(resolved_path, sizeof(resolved_path)))
{
- Error error;
File file;
error = file.Open(resolved_path, File::eOpenOptionRead);
if (error.Success())
error = file.Read (file_size, file_offset, data_sp);
}
+ else
+ {
+ error.SetErrorString("invalid file specification");
+ }
+ if (error_ptr)
+ *error_ptr = error;
return data_sp;
}
diff --git a/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp b/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
index 62d8545..12c104b 100644
--- a/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
+++ b/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
@@ -234,7 +234,7 @@
xcode_dir_path.append (xcode_select_prefix_dir);
xcode_dir_path.append ("/usr/share/xcode-select/xcode_dir_path");
temp_file_spec.SetFile(xcode_dir_path.c_str(), false);
- size_t bytes_read = temp_file_spec.ReadFileContents(0, developer_dir_path, sizeof(developer_dir_path));
+ size_t bytes_read = temp_file_spec.ReadFileContents(0, developer_dir_path, sizeof(developer_dir_path), NULL);
if (bytes_read > 0)
{
developer_dir_path[bytes_read] = '\0';
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index c31b0b1..3ff461d 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -2308,6 +2308,8 @@
case eVarSetOperationAssign:
case eVarSetOperationAppend:
{
+ m_expr_prefix_contents.clear();
+
if (!m_expr_prefix_file.GetCurrentValue().Exists())
{
err.SetErrorToGenericError ();
@@ -2315,15 +2317,19 @@
return;
}
- DataBufferSP file_contents = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
+ DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
- if (!file_contents && file_contents->GetByteSize() == 0)
+ if (err.Success())
{
- err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
- m_expr_prefix_contents.clear();
+ if (file_data_sp && file_data_sp->GetByteSize() > 0)
+ {
+ m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
+ }
+ else
+ {
+ err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
+ }
}
-
- m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize());
}
break;
case eVarSetOperationClear: