Fix a use-after-free in getPackageInterfacePathIfInSamePackage

Fix a use-after-free bug in package-name extraction code, where the
BumpPtrAllcoator is destroyed before a StringRef that uses the allocated
name is used.
This commit is contained in:
Steven Wu
2024-02-26 15:55:49 -08:00
parent 7b5502b410
commit aa5ef5773c

View File

@@ -611,7 +611,7 @@ SerializedModuleBaseName::getPackageInterfacePathIfInSamePackage(
if (fs.exists(packagePath)) {
// Read the interface file and extract its package-name argument value
StringRef result;
std::string result;
if (auto packageFile = llvm::MemoryBuffer::getFile(packagePath)) {
llvm::BumpPtrAllocator alloc;
llvm::StringSaver argSaver(alloc);