Skip to content

Commit 3612d2d

Browse files
Merge pull request #9750 from adrian-prantl/141553025
[lldb] Fix potential nullptr dereferences in string handling
2 parents cc1f091 + 798d9c7 commit 3612d2d

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

+29-23
Original file line numberDiff line numberDiff line change
@@ -2156,10 +2156,11 @@ static std::string GetSDKPathFromDebugInfo(std::string m_description,
21562156
auto [sdk, found_mismatch] = std::move(*sdk_or_err);
21572157

21582158
if (found_mismatch)
2159-
HEALTH_LOG_PRINTF("Unsupported mixing of public and internal SDKs in "
2160-
"'%s'. Mixed use of SDKs indicates use of different "
2161-
"toolchains, which is not supported.",
2162-
module.GetFileSpec().GetFilename().GetCString());
2159+
HEALTH_LOG_PRINTF(
2160+
"Unsupported mixing of public and internal SDKs in "
2161+
"'%s'. Mixed use of SDKs indicates use of different "
2162+
"toolchains, which is not supported.",
2163+
module.GetFileSpec().GetFilename().AsCString("<unknown module>"));
21632164

21642165
return GetSDKPath(m_description, std::move(sdk));
21652166
}
@@ -2557,9 +2558,10 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
25572558
swift_ast_sp->InitializeSearchPathOptions(module_search_paths,
25582559
framework_search_paths);
25592560
if (!swift_ast_sp->GetClangImporter()) {
2560-
LOG_PRINTF(GetLog(LLDBLog::Types),
2561-
"(\"%s\") returning NULL - couldn't create a ClangImporter",
2562-
module.GetFileSpec().GetFilename().AsCString("<anonymous>"));
2561+
LOG_PRINTF(
2562+
GetLog(LLDBLog::Types),
2563+
"(\"%s\") returning NULL - couldn't create a ClangImporter",
2564+
module.GetFileSpec().GetFilename().AsCString("<unknown module>"));
25632565
return {};
25642566
}
25652567

@@ -2607,10 +2609,11 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
26072609
swift_ast_sp->ImportSectionModules(module, module_names);
26082610
if (GetLog(LLDBLog::Types)) {
26092611
std::lock_guard<std::recursive_mutex> locker(g_log_mutex);
2610-
LOG_PRINTF(GetLog(LLDBLog::Types), "((Module*)%p, \"%s\") = %p",
2611-
static_cast<void *>(&module),
2612-
module.GetFileSpec().GetFilename().AsCString("<anonymous>"),
2613-
static_cast<void *>(swift_ast_sp.get()));
2612+
LOG_PRINTF(
2613+
GetLog(LLDBLog::Types), "((Module*)%p, \"%s\") = %p",
2614+
static_cast<void *>(&module),
2615+
module.GetFileSpec().GetFilename().AsCString("<unknown module>"),
2616+
static_cast<void *>(swift_ast_sp.get()));
26142617
}
26152618
}
26162619

@@ -4504,23 +4507,26 @@ void SwiftASTContext::RegisterSectionModules(
45044507
auto Result = swift::parseASTSection(*loader, section_data_ref, filter);
45054508
if (auto E = Result.takeError()) {
45064509
std::string error = toString(std::move(E));
4507-
LOG_PRINTF(GetLog(LLDBLog::Types),
4508-
"failed to parse AST section %zu/%zu in image \"%s\" "
4509-
"(filter=\"%s\"). %s",
4510-
n, total, module.GetFileSpec().GetFilename().GetCString(),
4511-
filter.str().c_str(), error.c_str());
4510+
LOG_PRINTF(
4511+
GetLog(LLDBLog::Types),
4512+
"failed to parse AST section %zu/%zu in image \"%s\" "
4513+
"(filter=\"%s\"). %s",
4514+
n, total,
4515+
module.GetFileSpec().GetFilename().AsCString("<unknown module>"),
4516+
filter.str().c_str(), error.c_str());
45124517
return;
45134518
}
45144519

45154520
// Collect the Swift module names referenced by the AST.
45164521
for (auto module_name : *Result) {
45174522
module_names.push_back(module_name);
4518-
LOG_PRINTF(GetLog(LLDBLog::Types),
4519-
"parsed module \"%s\" from Swift AST section %zu/%zu in "
4520-
"image \"%s\" (filter=\"%s\").",
4521-
module_name.c_str(), n, total,
4522-
module.GetFileSpec().GetFilename().GetCString(),
4523-
filter.str().c_str());
4523+
LOG_PRINTF(
4524+
GetLog(LLDBLog::Types),
4525+
"parsed module \"%s\" from Swift AST section %zu/%zu in "
4526+
"image \"%s\" (filter=\"%s\").",
4527+
module_name.c_str(), n, total,
4528+
module.GetFileSpec().GetFilename().AsCString("<unknown module>"),
4529+
filter.str().c_str());
45244530
}
45254531
};
45264532

@@ -4559,7 +4565,7 @@ void SwiftASTContext::ImportSectionModules(
45594565
LLDB_SCOPED_TIMER();
45604566

45614567
Progress progress("Loading Swift module dependencies",
4562-
module.GetFileSpec().GetFilename().AsCString(),
4568+
module.GetFileSpec().GetFilename().GetString(),
45634569
module_names.size());
45644570

45654571
size_t completion = 0;

0 commit comments

Comments
 (0)