From f927b34a148b27b24f37f062d5a0620b76430ade Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Mon, 12 Aug 2019 14:05:37 +0000 Subject: [PATCH] [llvm-readobj] Downgrade 'PT_DYNAMIC segment offset + size exceeds the size of the file' from an error to a warning Summary: This allows llvm-readobj to print other useful information for truncated files instead of giving up. Reviewers: jhenderson, grimar, MaskRay Reviewed By: jhenderson, grimar, MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66036 llvm-svn: 368576 --- llvm/test/Object/invalid.test | 6 +++--- llvm/test/tools/llvm-readobj/elf-malformed-pt-dynamic.test | 8 ++++---- llvm/tools/llvm-readobj/ELFDumper.cpp | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/llvm/test/Object/invalid.test b/llvm/test/Object/invalid.test index 09c8dfe..cddc0b9 100644 --- a/llvm/test/Object/invalid.test +++ b/llvm/test/Object/invalid.test @@ -489,9 +489,9 @@ Sections: ## than the object size. Check llvm-readobj reports it. # RUN: yaml2obj %s --docnum=23 -o %t23 -# RUN: not llvm-readobj --dyn-relocations %t23 2>&1 | FileCheck --check-prefix=DYN-TABLE-PHDR %s +# RUN: llvm-readobj --dyn-relocations %t23 2>&1 | FileCheck --check-prefix=DYN-TABLE-PHDR %s -# DYN-TABLE-PHDR: error: PT_DYNAMIC segment offset + size exceeds the size of the file +# DYN-TABLE-PHDR: warning: PT_DYNAMIC segment offset + size exceeds the size of the file --- !ELF FileHeader: @@ -515,7 +515,7 @@ ProgramHeaders: ## than the object size. Check llvm-readobj reports it. # RUN: yaml2obj %s --docnum=24 -o %t24 -# RUN: not llvm-readobj --dyn-relocations %t24 2>&1 \ +# RUN: llvm-readobj --dyn-relocations %t24 2>&1 \ # RUN: | FileCheck --check-prefix=DYN-TABLE-PHDR %s --- !ELF diff --git a/llvm/test/tools/llvm-readobj/elf-malformed-pt-dynamic.test b/llvm/test/tools/llvm-readobj/elf-malformed-pt-dynamic.test index db229b1..c234d48 100644 --- a/llvm/test/tools/llvm-readobj/elf-malformed-pt-dynamic.test +++ b/llvm/test/tools/llvm-readobj/elf-malformed-pt-dynamic.test @@ -1,5 +1,5 @@ # If the offset and/or size fields of the PT_DYNAMIC field become corrupted, -# we should report a sensible error message. +# we should report a sensible message. # Creating such a malformed file is hard. The easiest way to simulate it is to # truncate the file. Note that the section headers must first be stripped or @@ -13,14 +13,14 @@ # within the file. # RUN: cp %t.stripped %t.truncated1 # RUN: %python -c "with open(r'%t.truncated1', 'r+') as f: f.truncate(0x1001)" -# RUN: not llvm-readobj %t.truncated1 --dynamic-table 2>&1 | FileCheck %s +# RUN: llvm-readobj %t.truncated1 --dynamic-table 2>&1 | FileCheck %s # Test case where the offset is too large to be in the file. # RUN: cp %t.stripped %t.truncated2 # RUN: %python -c "with open(r'%t.truncated2', 'r+') as f: f.truncate(0xFFF)" -# RUN: not llvm-readobj %t.truncated2 --dynamic-table 2>&1 | FileCheck %s +# RUN: llvm-readobj %t.truncated2 --dynamic-table 2>&1 | FileCheck %s -# CHECK: error: PT_DYNAMIC segment offset + size exceeds the size of the file +# CHECK: warning: PT_DYNAMIC segment offset + size exceeds the size of the file --- !ELF FileHeader: diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index afff087..78216ef 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1439,9 +1439,11 @@ void ELFDumper::loadDynamicTable(const ELFFile *Obj) { return; if (DynamicPhdr->p_offset + DynamicPhdr->p_filesz > - ObjF->getMemoryBufferRef().getBufferSize()) - reportError( + ObjF->getMemoryBufferRef().getBufferSize()) { + reportWarning( "PT_DYNAMIC segment offset + size exceeds the size of the file"); + return; + } if (!DynamicSec) { DynamicTable = createDRIFrom(DynamicPhdr, sizeof(Elf_Dyn)); -- 2.7.4