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

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 6 01:55:28 PDT 2021


Author: Esme-Yi
Date: 2021-08-06T08:54:02Z
New Revision: 2919ac8971727930d939aeccfc9a4e50ad6b9884

URL: https://github.com/llvm/llvm-project/commit/2919ac8971727930d939aeccfc9a4e50ad6b9884
DIFF: https://github.com/llvm/llvm-project/commit/2919ac8971727930d939aeccfc9a4e50ad6b9884.diff

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

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107398

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index 8cdbd95ba8806..dc4a3031f914f 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -54,10 +54,16 @@ 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) {
-    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


        


More information about the llvm-commits mailing list