[llvm] 3df1e7e - [llvm-readobj][XCOFF] Warn about invalid offset
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 3 20:11:34 PDT 2021
Author: Vitaly Buka
Date: 2021-08-03T20:11:26-07:00
New Revision: 3df1e7e6f05e42df813accf8ec89e800515b6f70
URL: https://github.com/llvm/llvm-project/commit/3df1e7e6f05e42df813accf8ec89e800515b6f70
DIFF: https://github.com/llvm/llvm-project/commit/3df1e7e6f05e42df813accf8ec89e800515b6f70.diff
LOG: [llvm-readobj][XCOFF] Warn about invalid offset
Followup for D105522
Differential Revision: https://reviews.llvm.org/D107398
Added:
Modified:
llvm/test/tools/llvm-readobj/XCOFF/string-table.yaml
llvm/tools/llvm-readobj/ObjDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/XCOFF/string-table.yaml b/llvm/test/tools/llvm-readobj/XCOFF/string-table.yaml
index c5d15f2521599..7b537c1fe4c97 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/string-table.yaml
+++ b/llvm/test/tools/llvm-readobj/XCOFF/string-table.yaml
@@ -32,9 +32,10 @@ Symbols:
## There is no string table.
# RUN: yaml2obj --docnum=3 %s -o %t3
-# RUN: llvm-readobj --string-table %t3 | FileCheck %s --check-prefix=NO-STRTBL
+# RUN: llvm-readobj --string-table %t3 2>&1 | FileCheck %s --check-prefix=NO-STRTBL
# NO-STRTBL: StringTable {
+# NO-STRTBL-NEXT: error: offset is out of string contents
# NO-STRTBL-NEXT: }
--- !XCOFF
diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index d7120807dd968..8cdbd95ba8806 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -54,8 +54,10 @@ static void printAsPrintable(raw_ostream &W, const uint8_t *Start, size_t Len) {
void ObjDumper::printAsStringList(StringRef StringContent,
size_t StringDataOffset) {
- if (StringContent.size() < StringDataOffset)
+ if (StringContent.size() < StringDataOffset) {
+ reportUniqueWarning("error: offset is out of string contents");
return;
+ }
const uint8_t *StrContent = StringContent.bytes_begin();
// Some formats contain additional metadata at the start which should not be
// interpreted as strings. Skip these bytes, but account for them in the
More information about the llvm-commits
mailing list