summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-10-24 15:52:05 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-10-24 15:52:05 +0000
commit014601d56e0778b7b7a61f53923bfcbc5a92bc7f (patch)
tree5566a7557fd502c2327df36e77f5980e862468f5 /llvm/lib/Object/MachOObjectFile.cpp
parentaa1b35590f8284aee769ba1b239713a75f3ca6f7 (diff)
downloadbcm5719-llvm-014601d56e0778b7b7a61f53923bfcbc5a92bc7f.tar.gz
bcm5719-llvm-014601d56e0778b7b7a61f53923bfcbc5a92bc7f.zip
[Object] Fix MachO's getUuid to return a pointer into the object instead of a dangling ArrayRef.
This works because uuid's are always little endian so it's not swapped. Fixes use-after-return reported by asan. llvm-svn: 220567
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 0bd61cecb57..ad2fd03f9ee 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -2460,8 +2460,9 @@ ArrayRef<uint8_t> MachOObjectFile::getDyldInfoExportsTrie() const {
ArrayRef<uint8_t> MachOObjectFile::getUuid() const {
if (!UuidLoadCmd)
return ArrayRef<uint8_t>();
- MachO::uuid_command Uuid = getStruct<MachO::uuid_command>(this, UuidLoadCmd);
- return ArrayRef<uint8_t>(Uuid.uuid, 16);
+ // Returning a pointer is fine as uuid doesn't need endian swapping.
+ const char *Ptr = UuidLoadCmd + offsetof(MachO::uuid_command, uuid);
+ return ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Ptr), 16);
}
StringRef MachOObjectFile::getStringTableData() const {
OpenPOWER on IntegriCloud