From: Benjamin Kramer Date: Fri, 24 Oct 2014 15:52:05 +0000 (+0000) Subject: [Object] Fix MachO's getUuid to return a pointer into the object instead of a danglin... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=5ea04462dcb1396f050c7eca0e490fe25d5a1e77 [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220567 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 0bd61cecb57..ad2fd03f9ee 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -2460,8 +2460,9 @@ ArrayRef MachOObjectFile::getDyldInfoExportsTrie() const { ArrayRef MachOObjectFile::getUuid() const { if (!UuidLoadCmd) return ArrayRef(); - MachO::uuid_command Uuid = getStruct(this, UuidLoadCmd); - return ArrayRef(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(reinterpret_cast(Ptr), 16); } StringRef MachOObjectFile::getStringTableData() const {