]> granicus.if.org Git - clang/commitdiff
Fix use-after-free found by address-san on -r322028.
authorErich Keane <erich.keane@intel.com>
Tue, 9 Jan 2018 01:09:12 +0000 (01:09 +0000)
committerErich Keane <erich.keane@intel.com>
Tue, 9 Jan 2018 01:09:12 +0000 (01:09 +0000)
r322028 attempted to remove something from the "Manglings"
list when it was no longer valid, and did so with 'erase'.

However, StringRefs to these were stored, so these became
dangling references.  This patch changes to using 'remove' instead
of 'erase' to keep the strings valid.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322052 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp

index 85bd53741e180131bf16cfcc44872f5a6d627338..32c9b28124ab304214ae903a78da08e0b849a141 100644 (file)
@@ -813,7 +813,11 @@ void CodeGenModule::UpdateMultiVersionNames(GlobalDecl GD,
     // This is so that if the initial version was already the 'default'
     // version, we don't try to update it.
     if (OtherName != NonTargetName) {
-      Manglings.erase(NonTargetName);
+      // Remove instead of erase, since others may have stored the StringRef
+      // to this.
+      const auto ExistingRecord = Manglings.find(NonTargetName);
+      if (ExistingRecord != std::end(Manglings))
+        Manglings.remove(&(*ExistingRecord));
       auto Result = Manglings.insert(std::make_pair(OtherName, OtherGD));
       MangledDeclNames[OtherGD.getCanonicalDecl()] = Result.first->first();
       if (llvm::GlobalValue *Entry = GetGlobalValue(NonTargetName))