From 2e940a11e7c64718d36955e4ca68fa87aa9d5a9d Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Tue, 17 Jun 2014 14:14:33 +0000 Subject: [PATCH] Avoid crashing on invalid or unreadable ELF core Issue discovered during the GSoC 2014 project implementing FreeBSD kernel support. The existing elf-core Process plugin crashed trying to read from /dev/mem (the kernel memory device). Patch by Mike Ma. llvm-svn: 211102 --- lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp index 0fa253d..087ee49 100644 --- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp +++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp @@ -63,7 +63,8 @@ ProcessElfCore::CreateInstance (Target &target, Listener &listener, const FileSp const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr); lldb::DataBufferSP data_sp (crash_file->ReadFileContents(0, header_size)); - if (data_sp->GetByteSize() == header_size && elf::ELFHeader::MagicBytesMatch (data_sp->GetBytes())) + if (data_sp && data_sp->GetByteSize() == header_size && + elf::ELFHeader::MagicBytesMatch (data_sp->GetBytes())) { elf::ELFHeader elf_header; DataExtractor data(data_sp, lldb::eByteOrderLittle, 4); -- 2.7.4