Fix use-after-free found by address-san on -r322028.

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.

llvm-svn: 322052
This commit is contained in:
Erich Keane 2018-01-09 01:09:12 +00:00
parent 7e10987b12
commit bc40c5c68f
1 changed files with 5 additions and 1 deletions

View 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))