Skip to content

Commit 4b13c86

Browse files
author
Mogball
committed
[ORC] Fix heap-use-after-free error in MachODebugObjectSynthesizer.cpp
At line 191, `addSymbol` takes the name by reference but does not make an internal copy to the string, meaning the local `optional<std::string>` would get freed and leave Orc with a dangling pointer. Fix this by just using an `optional<StringRef>` instead.
1 parent 466ea89 commit 4b13c86

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class MachODebugObjectSynthesizer : public MachODebugObjectSynthesizerBase {
156156
}
157157
}
158158

159-
std::optional<std::string> FileName;
159+
std::optional<StringRef> FileName;
160160
if (!DebugLineSectionData.empty()) {
161161
auto DWARFCtx = DWARFContext::create(DebugSectionMap, G.getPointerSize(),
162162
G.getEndianness());
@@ -169,15 +169,13 @@ class MachODebugObjectSynthesizer : public MachODebugObjectSynthesizerBase {
169169
// Try to parse line data. Consume error on failure.
170170
if (auto Err = LineTable.parse(DebugLineData, &Offset, *DWARFCtx, nullptr,
171171
consumeError)) {
172-
handleAllErrors(
173-
std::move(Err),
174-
[&](ErrorInfoBase &EIB) {
175-
LLVM_DEBUG({
176-
dbgs() << "Cannot parse line table for \"" << G.getName() << "\": ";
177-
EIB.log(dbgs());
178-
dbgs() << "\n";
179-
});
172+
handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
173+
LLVM_DEBUG({
174+
dbgs() << "Cannot parse line table for \"" << G.getName() << "\": ";
175+
EIB.log(dbgs());
176+
dbgs() << "\n";
180177
});
178+
});
181179
} else {
182180
if (!LineTable.Prologue.FileNames.empty())
183181
FileName = *dwarf::toString(LineTable.Prologue.FileNames[0].Name);
@@ -187,7 +185,7 @@ class MachODebugObjectSynthesizer : public MachODebugObjectSynthesizerBase {
187185
// If no line table (or unable to use) then use graph name.
188186
// FIXME: There are probably other debug sections we should look in first.
189187
if (!FileName)
190-
FileName = G.getName();
188+
FileName = StringRef(G.getName());
191189

192190
Builder.addSymbol("", MachO::N_SO, 0, 0, 0);
193191
Builder.addSymbol(*FileName, MachO::N_SO, 0, 0, 0);

0 commit comments

Comments
 (0)