summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ObjectFile
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2013-04-16 16:51:19 +0000
committerGreg Clayton <gclayton@apple.com>2013-04-16 16:51:19 +0000
commitd37d6927c5f5267ed6886fb6fe18e88150a95ca2 (patch)
tree69286dc11ff0d636f0ed7f548f2be9a2dec7f7cf /lldb/source/Plugins/ObjectFile
parente90fe76abd288e3b47d09852071bad7a11cede8d (diff)
downloadbcm5719-llvm-d37d6927c5f5267ed6886fb6fe18e88150a95ca2.tar.gz
bcm5719-llvm-d37d6927c5f5267ed6886fb6fe18e88150a95ca2.zip
<rdar://problem/13468295>
Show an error message when we have a corrupt mach-o file where the LC_SEGMENT or LC_SEGMENT_64 load command have file offsets or file offsets + sizes that extend beyond the end of the file. llvm-svn: 179605
Diffstat (limited to 'lldb/source/Plugins/ObjectFile')
-rw-r--r--lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 42f21f7bb36..7ec1b48b0c3 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -844,25 +844,36 @@ ObjectFileMachO::ParseSections ()
load_cmd.filesize = m_data.GetAddress(&offset);
if (m_length != 0 && load_cmd.filesize != 0)
{
+ if (load_cmd.fileoff > m_length)
+ {
+ // We have a load command that says it extends past the end of hte file. This is likely
+ // a corrupt file. We don't have any way to return an error condition here (this method
+ // was likely invokved from something like ObjectFile::GetSectionList()) -- all we can do
+ // is null out the SectionList vector and if a process has been set up, dump a message
+ // to stdout. The most common case here is core file debugging with a truncated file.
+ const char *lc_segment_name = load_cmd.cmd == LoadCommandSegment64 ? "LC_SEGMENT_64" : "LC_SEGMENT";
+ GetModule()->ReportError("is a corrupt mach-o file: load command %u %s has a fileoff (0x%" PRIx64 ") that extends beyond the end of the file (0x%" PRIx64 ")",
+ i,
+ lc_segment_name,
+ load_cmd.fileoff,
+ m_length);
+ m_sections_ap->Clear();
+ return 0;
+ }
+
if (load_cmd.fileoff + load_cmd.filesize > m_length)
{
// We have a load command that says it extends past the end of hte file. This is likely
// a corrupt file. We don't have any way to return an error condition here (this method
// was likely invokved from something like ObjectFile::GetSectionList()) -- all we can do
// is null out the SectionList vector and if a process has been set up, dump a message
- // to stdout. The most common case here is core file debugging with a truncated file - and
- // in that case we don't have a Process yet so nothing will be printed. Not really ideal;
- // the ObjectFile needs some way of reporting an error message for methods like GetSectionList
- // which fail.
- ProcessSP process_sp (m_process_wp.lock());
- if (process_sp)
- {
- Stream *s = &process_sp->GetTarget().GetDebugger().GetOutputStream();
- if (s)
- {
- s->Printf ("Corrupt/invalid Mach-O object file -- a load command extends past the end of the file.\n");
- }
- }
+ // to stdout. The most common case here is core file debugging with a truncated file.
+ const char *lc_segment_name = load_cmd.cmd == LoadCommandSegment64 ? "LC_SEGMENT_64" : "LC_SEGMENT";
+ GetModule()->ReportError("is a corrupt mach-o file: load command %u %s has a fileoff + filesize (0x%" PRIx64 ") that extends beyond the end of the file (0x%" PRIx64 ")",
+ i,
+ lc_segment_name,
+ load_cmd.fileoff + load_cmd.filesize,
+ m_length);
m_sections_ap->Clear();
return 0;
}
OpenPOWER on IntegriCloud