Skip to content

Commit 10ceca8

Browse files
aahrunda-viper
andauthored
[lldb-dap] Fix segfault in JSONUtils.cpp when GetUUIDString() returns nullptr (#169844)
When creating a stack frame in JSONUtils.cpp CreateStackFrame() the code constructs a std::string from module.GetUUIDString(), which can return nullptr in some cases (as documented in the implementation of SBModule::GetUUIDString()). This causes a segmentation fault when passed to the std::string constructor. This fix adds a null check before constructing the UUID string, falling back to an empty string if nullptr is returned. The existing empty check ensures the moduleId field is omitted from the JSON when no UUID exists. rdar://163811812 --------- Co-authored-by: Ebuka Ezike <yerimyah1@gmail.com>
1 parent 7b6bf8b commit 10ceca8

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ void CompileUnitsRequestHandler::operator()(
6060
llvm::json::Object body;
6161
llvm::json::Array units;
6262
const auto *arguments = request.getObject("arguments");
63-
const std::string module_id =
64-
GetString(arguments, "moduleId").value_or("").str();
63+
const llvm::StringRef module_id =
64+
GetString(arguments, "moduleId").value_or("");
6565
int num_modules = dap.target.GetNumModules();
6666
for (int i = 0; i < num_modules; i++) {
6767
auto curr_module = dap.target.GetModuleAtIndex(i);
68-
if (module_id == curr_module.GetUUIDString()) {
68+
if (module_id == llvm::StringRef(curr_module.GetUUIDString())) {
6969
int num_units = curr_module.GetNumCompileUnits();
7070
for (int j = 0; j < num_units; j++) {
7171
auto curr_unit = curr_module.GetCompileUnitAtIndex(j);

lldb/tools/lldb-dap/JSONUtils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,8 @@ llvm::json::Value CreateStackFrame(DAP &dap, lldb::SBFrame &frame,
554554

555555
lldb::SBModule module = frame.GetModule();
556556
if (module.IsValid()) {
557-
std::string uuid = module.GetUUIDString();
558-
if (!uuid.empty())
559-
object.try_emplace("moduleId", uuid);
557+
if (const llvm::StringRef uuid = module.GetUUIDString(); !uuid.empty())
558+
object.try_emplace("moduleId", uuid.str());
560559
}
561560

562561
return llvm::json::Value(std::move(object));

0 commit comments

Comments
 (0)