From c92ff2a3c449d2de502dc8444a0fdad5b4c42ff4 Mon Sep 17 00:00:00 2001 From: "revunov.denis@huawei.com" Date: Mon, 14 Nov 2022 13:25:20 +0000 Subject: [PATCH] [BOLT][NFC] Fix possible use-after-free 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. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D137616 --- bolt/lib/Core/BinaryContext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index 6a01ab4d17f6..d09d8af9e29b 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -2036,9 +2036,9 @@ void BinaryContext::renameSection(BinarySection &Section, 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);