From 230dbd2b22b0df965f8f043d4ada5ea1fc54315b Mon Sep 17 00:00:00 2001 From: Francis Visoiu Mistrih Date: Mon, 19 Nov 2018 17:19:50 +0000 Subject: [PATCH] [llvm-nm] Fix use-after-free for MachOUniversalBinaries MachOObjectFile::getHostArch() returns a temporary, and getArchName returns a StringRef pointing to a temporary std::string. No tests since it doesn't trigger any errors except with the sanitizers. llvm-svn: 347230 --- tools/llvm-nm/llvm-nm.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index ad0afd4b0aa..88217a5403f 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -1889,7 +1889,8 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { // No architecture flags were specified so if this contains a slice that // matches the host architecture dump only that. if (!ArchAll) { - StringRef HostArchName = MachOObjectFile::getHostArch().getArchName(); + Triple HostTriple = MachOObjectFile::getHostArch(); + StringRef HostArchName = HostTriple.getArchName(); for (MachOUniversalBinary::object_iterator I = UB->begin_objects(), E = UB->end_objects(); I != E; ++I) {