[llvm] r331746 - Object: Find terminator correctly when reading long filenames in GNU archives (PR37244)
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Tue May 8 01:22:58 PDT 2018
Author: hans
Date: Tue May 8 01:22:58 2018
New Revision: 331746
URL: http://llvm.org/viewvc/llvm-project?rev=331746&view=rev
Log:
Object: Find terminator correctly when reading long filenames in GNU archives (PR37244)
The code was previously relying on there being a null terminator
somewhere in (or after) the string table, something made less likely by
r330786.
Differential Revision: https://reviews.llvm.org/D46527
Modified:
llvm/trunk/lib/Object/Archive.cpp
Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=331746&r1=331745&r2=331746&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Tue May 8 01:22:58 2018
@@ -175,15 +175,19 @@ Expected<StringRef> ArchiveMemberHeader:
"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/")) {
More information about the llvm-commits
mailing list