[Lldb-commits] [lldb] r179152 - When ObjectFileMachO::ParseSections() notices that it has a truncated file, zero out the
Jason Molenda
jmolenda at apple.com
Tue Apr 9 22:58:57 PDT 2013
Author: jmolenda
Date: Wed Apr 10 00:58:57 2013
New Revision: 179152
URL: http://llvm.org/viewvc/llvm-project?rev=179152&view=rev
Log:
When ObjectFileMachO::ParseSections() notices that it has a truncated file, zero out the
SectionList so we don't try to do anything with this file. Currently we end up crashing
later in the debug session when we read past the end of the file -- this at least gets us
closer with something like ProcessMachCore printing "error: core file has no sections".
<rdar://problem/13468295>
Modified:
lldb/trunk/include/lldb/Core/Section.h
lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Modified: lldb/trunk/include/lldb/Core/Section.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Section.h?rev=179152&r1=179151&r2=179152&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Section.h (original)
+++ lldb/trunk/include/lldb/Core/Section.h Wed Apr 10 00:58:57 2013
@@ -88,6 +88,12 @@ public:
void
Finalize ();
+ void
+ Clear ()
+ {
+ m_sections.clear();
+ }
+
protected:
collection m_sections;
};
Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=179152&r1=179151&r2=179152&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Wed Apr 10 00:58:57 2013
@@ -15,6 +15,7 @@
#include "lldb/lldb-private-log.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/DataBuffer.h"
+#include "lldb/Core/Debugger.h"
#include "lldb/Core/FileSpecList.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
@@ -836,6 +837,31 @@ ObjectFileMachO::ParseSections ()
load_cmd.vmsize = m_data.GetAddress(&offset);
load_cmd.fileoff = m_data.GetAddress(&offset);
load_cmd.filesize = m_data.GetAddress(&offset);
+ if (m_length != 0 && load_cmd.filesize != 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");
+ }
+ }
+ m_sections_ap->Clear();
+ return 0;
+ }
+ }
if (m_data.GetU32(&offset, &load_cmd.maxprot, 4))
{
More information about the lldb-commits
mailing list