Skip to content

Commit

Permalink
Object: Find terminator correctly when reading long filenames in GNU …
Browse files Browse the repository at this point in the history
…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

llvm-svn: 331746
  • Loading branch information
zmodem committed May 8, 2018
1 parent 98a1cab commit 5e6e6cc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions llvm/lib/Object/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,19 @@ Expected<StringRef> ArchiveMemberHeader::getName(uint64_t Size) const {
"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/")) {
Expand Down

0 comments on commit 5e6e6cc

Please sign in to comment.