[PATCH] D137616: [BOLT][NFC] Fix possible use-after-free

Denis Revunov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 01:01:22 PST 2022


treapster created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
treapster requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

If NewName twine has reference to the old name, then after `Section.Name = NewName.str();` this reference is invalidated, so we cannot use `NewName.str()` anymore.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137616

Files:
  bolt/lib/Core/BinaryContext.cpp


Index: bolt/lib/Core/BinaryContext.cpp
===================================================================
--- bolt/lib/Core/BinaryContext.cpp
+++ bolt/lib/Core/BinaryContext.cpp
@@ -2036,9 +2036,9 @@
   deregisterSectionName(Section);
 
   Section.Name = NewName.str();
-  Section.setOutputName(NewName);
+  Section.setOutputName(Section.Name);
 
-  NameToSection.insert(std::make_pair(NewName.str(), &Section));
+  NameToSection.insert(std::make_pair(Section.Name, &Section));
 
   // Reinsert with the new name.
   Sections.insert(&Section);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137616.473910.patch
Type: text/x-patch
Size: 545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221108/96f7ee9f/attachment.bin>


More information about the llvm-commits mailing list