Skip to content

Commit 798d9c7

Browse files
committed
[lldb] Fix potential nullptr dereferences in string handling
rdar://141553025
1 parent 99f0b04 commit 798d9c7

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

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

Lines changed: 29 additions & 23 deletions
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

@@ -4484,23 +4487,26 @@ void SwiftASTContext::RegisterSectionModules(
44844487
auto Result = swift::parseASTSection(*loader, section_data_ref, filter);
44854488
if (auto E = Result.takeError()) {
44864489
std::string error = toString(std::move(E));
4487-
LOG_PRINTF(GetLog(LLDBLog::Types),
4488-
"failed to parse AST section %zu/%zu in image \"%s\" "
4489-
"(filter=\"%s\"). %s",
4490-
n, total, module.GetFileSpec().GetFilename().GetCString(),
4491-
filter.str().c_str(), error.c_str());
4490+
LOG_PRINTF(
4491+
GetLog(LLDBLog::Types),
4492+
"failed to parse AST section %zu/%zu in image \"%s\" "
4493+
"(filter=\"%s\"). %s",
4494+
n, total,
4495+
module.GetFileSpec().GetFilename().AsCString("<unknown module>"),
4496+
filter.str().c_str(), error.c_str());
44924497
return;
44934498
}
44944499

44954500
// Collect the Swift module names referenced by the AST.
44964501
for (auto module_name : *Result) {
44974502
module_names.push_back(module_name);
4498-
LOG_PRINTF(GetLog(LLDBLog::Types),
4499-
"parsed module \"%s\" from Swift AST section %zu/%zu in "
4500-
"image \"%s\" (filter=\"%s\").",
4501-
module_name.c_str(), n, total,
4502-
module.GetFileSpec().GetFilename().GetCString(),
4503-
filter.str().c_str());
4503+
LOG_PRINTF(
4504+
GetLog(LLDBLog::Types),
4505+
"parsed module \"%s\" from Swift AST section %zu/%zu in "
4506+
"image \"%s\" (filter=\"%s\").",
4507+
module_name.c_str(), n, total,
4508+
module.GetFileSpec().GetFilename().AsCString("<unknown module>"),
4509+
filter.str().c_str());
45044510
}
45054511
};
45064512

@@ -4539,7 +4545,7 @@ void SwiftASTContext::ImportSectionModules(
45394545
LLDB_SCOPED_TIMER();
45404546

45414547
Progress progress("Loading Swift module dependencies",
4542-
module.GetFileSpec().GetFilename().AsCString(),
4548+
module.GetFileSpec().GetFilename().GetString(),
45434549
module_names.size());
45444550

45454551
size_t completion = 0;

0 commit comments

Comments
 (0)