[PATCH] D46527: Object: Find terminator correctly when getting long filenames from GNU archives

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 8 01:26:39 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL331746: Object: Find terminator correctly when reading long filenames in GNU archives… (authored by hans, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46527?vs=145467&id=145644#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46527

Files:
  llvm/trunk/lib/Object/Archive.cpp


Index: llvm/trunk/lib/Object/Archive.cpp
===================================================================
--- llvm/trunk/lib/Object/Archive.cpp
+++ llvm/trunk/lib/Object/Archive.cpp
@@ -175,15 +175,19 @@
                             "the end of the string table for archive member "
                             "header at offset " + Twine(ArchiveOffset));
     }
-    const char *addr = Parent->getStringTable().begin() + StringOffset;
 
     // GNU long file names end with a "/\n".
     if (Parent->kind() == Archive::K_GNU ||
         Parent->kind() == Archive::K_GNU64) {
-      StringRef::size_type End = StringRef(addr).find('\n');
-      return StringRef(addr, End - 1);
+      size_t End = Parent->getStringTable().find('\n', /*From=*/StringOffset);
+      if (End == StringRef::npos || End < 1 ||
+          Parent->getStringTable()[End - 1] != '/') {
+        return malformedError("string table at long name offset " +
+                              Twine(StringOffset) + "not terminated");
+      }
+      return Parent->getStringTable().slice(StringOffset, End - 1);
     }
-    return addr;
+    return Parent->getStringTable().begin() + StringOffset;
   }
 
   if (Name.startswith("#1/")) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46527.145644.patch
Type: text/x-patch
Size: 1210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180508/295ab280/attachment.bin>


More information about the llvm-commits mailing list