[llvm-readobj][XCOFF] Warn about invalid offset

Followup for D105522

Differential Revision: https://reviews.llvm.org/D107398
This commit is contained in:
Vitaly Buka 2021-08-03 13:14:52 -07:00
parent b16c37fa2c
commit 3df1e7e6f0
2 changed files with 5 additions and 2 deletions

View File

@ -32,9 +32,10 @@ Symbols:
## There is no string table. ## There is no string table.
# RUN: yaml2obj --docnum=3 %s -o %t3 # 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: StringTable {
# NO-STRTBL-NEXT: error: offset is out of string contents
# NO-STRTBL-NEXT: } # NO-STRTBL-NEXT: }
--- !XCOFF --- !XCOFF

View File

@ -54,8 +54,10 @@ static void printAsPrintable(raw_ostream &W, const uint8_t *Start, size_t Len) {
void ObjDumper::printAsStringList(StringRef StringContent, void ObjDumper::printAsStringList(StringRef StringContent,
size_t StringDataOffset) { size_t StringDataOffset) {
if (StringContent.size() < StringDataOffset) if (StringContent.size() < StringDataOffset) {
reportUniqueWarning("error: offset is out of string contents");
return; return;
}
const uint8_t *StrContent = StringContent.bytes_begin(); const uint8_t *StrContent = StringContent.bytes_begin();
// Some formats contain additional metadata at the start which should not be // Some formats contain additional metadata at the start which should not be
// interpreted as strings. Skip these bytes, but account for them in the // interpreted as strings. Skip these bytes, but account for them in the