[llvm-commits] [llvm] r172026 - /llvm/trunk/lib/Object/Archive.cpp
Michael J. Spencer
bigcheesegs at gmail.com
Wed Jan 9 17:05:34 PST 2013
Author: mspencer
Date: Wed Jan 9 19:05:34 2013
New Revision: 172026
URL: http://llvm.org/viewvc/llvm-project?rev=172026&view=rev
Log:
[Object][Archive] Fix name handling with bsd style long names.
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=172026&r1=172025&r2=172026&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Wed Jan 9 19:05:34 2013
@@ -49,7 +49,8 @@
uint64_t getSize() const {
uint64_t ret;
- StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, ret);
+ if (StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, ret))
+ llvm_unreachable("Size is not an integer.");
return ret;
}
};
@@ -111,7 +112,8 @@
// It's a long name.
// Get the offset.
std::size_t offset;
- name.substr(1).getAsInteger(10, offset);
+ if (name.substr(1).rtrim(" ").getAsInteger(10, offset))
+ llvm_unreachable("Long name offset is not an integer");
const char *addr = Parent->StringTable->Data.begin()
+ sizeof(ArchiveMemberHeader)
+ offset;
@@ -134,8 +136,9 @@
return object_error::success;
} else if (name.startswith("#1/")) {
uint64_t name_size;
- name.substr(3).getAsInteger(10, name_size);
- Result = Data.substr(0, name_size);
+ if (name.substr(3).rtrim(" ").getAsInteger(10, name_size))
+ llvm_unreachable("Long name length is not an ingeter");
+ Result = Data.substr(sizeof(ArchiveMemberHeader), name_size);
return object_error::success;
}
// It's a simple name.
@@ -152,21 +155,24 @@
StringRef name = ToHeader(Data.data())->getName();
if (name.startswith("#1/")) {
uint64_t name_size;
- name.substr(3).getAsInteger(10, name_size);
+ if (name.substr(3).rtrim(" ").getAsInteger(10, name_size))
+ llvm_unreachable("Long name length is not an integer");
size -= name_size;
}
return size;
}
MemoryBuffer *Archive::Child::getBuffer() const {
- StringRef name;
- if (getName(name)) return NULL;
+ StringRef name = ToHeader(Data.data())->getName();
int size = sizeof(ArchiveMemberHeader);
if (name.startswith("#1/")) {
uint64_t name_size;
- name.substr(3).getAsInteger(10, name_size);
+ if (name.substr(3).rtrim(" ").getAsInteger(10, name_size))
+ llvm_unreachable("Long name length is not an integer");
size += name_size;
}
+ if (getName(name))
+ return 0;
return MemoryBuffer::getMemBuffer(Data.substr(size, getSize()),
name,
false);
More information about the llvm-commits
mailing list