[PATCH] D107398: [llvm-readobj][XCOFF] Warn about invalid offset

Esme Yi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 6 01:55:34 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2919ac897172: [llvm-readobj][XCOFF] Warn about invalid offset (authored by Esme).

Changed prior to commit:
  https://reviews.llvm.org/D107398?vs=364004&id=364726#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107398/new/

https://reviews.llvm.org/D107398

Files:
  llvm/tools/llvm-readobj/ObjDumper.cpp


Index: llvm/tools/llvm-readobj/ObjDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ObjDumper.cpp
+++ llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -54,10 +54,16 @@
 
 void ObjDumper::printAsStringList(StringRef StringContent,
                                   size_t StringDataOffset) {
-  if (StringContent.size() < StringDataOffset) {
-    reportUniqueWarning("error: offset is out of string contents");
+  size_t StrSize = StringContent.size();
+  if (StrSize == 0)
+    return;
+  if (StrSize < StringDataOffset) {
+    reportUniqueWarning("offset (0x" + Twine::utohexstr(StringDataOffset) +
+                        ") is past the end of the contents (size 0x" +
+                        Twine::utohexstr(StrSize) + ")");
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107398.364726.patch
Type: text/x-patch
Size: 1017 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210806/92a740cb/attachment.bin>


More information about the llvm-commits mailing list