Skip to content

Commit e34c383

Browse files
authored
Merge pull request #1132 from adrian-prantl/resourcedir-master-2
Fix a use-after-free in GetSwiftStdlibOSDir.
2 parents 882b4e4 + 26cda25 commit e34c383

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

lldb/include/lldb/Symbol/SwiftASTContext.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ class SwiftASTContext : public TypeSystemSwift {
12281228
void RemapClangImporterOptions(const PathMappingList &path_map);
12291229

12301230
/// Infer the appropriate Swift resource directory for a target triple.
1231-
std::string GetResourceDir(const llvm::Triple &target);
1231+
llvm::StringRef GetResourceDir(const llvm::Triple &target);
12321232

12331233
/// Implementation of \c GetResourceDir.
12341234
static std::string GetResourceDir(llvm::StringRef platform_sdk_path,
@@ -1240,8 +1240,8 @@ class SwiftASTContext : public TypeSystemSwift {
12401240

12411241
/// Return the name of the OS-specific subdirectory containing the
12421242
/// Swift stdlib needed for \p target.
1243-
static llvm::StringRef GetSwiftStdlibOSDir(const llvm::Triple &target,
1244-
const llvm::Triple &host);
1243+
static std::string GetSwiftStdlibOSDir(const llvm::Triple &target,
1244+
const llvm::Triple &host);
12451245
};
12461246

12471247
class SwiftASTContextForExpressions : public SwiftASTContext {

lldb/source/Symbol/SwiftASTContext.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,8 @@ static SDKTypeMinVersion GetSDKType(const llvm::Triple &target,
995995

996996
/// Return the name of the OS-specific subdirectory containing the
997997
/// Swift stdlib needed for \p target.
998-
StringRef SwiftASTContext::GetSwiftStdlibOSDir(const llvm::Triple &target,
999-
const llvm::Triple &host) {
998+
std::string SwiftASTContext::GetSwiftStdlibOSDir(const llvm::Triple &target,
999+
const llvm::Triple &host) {
10001000
auto sdk = GetSDKType(target, host);
10011001
XcodeSDK::Info sdk_info;
10021002
sdk_info.type = sdk.sdk_type;
@@ -1006,7 +1006,7 @@ StringRef SwiftASTContext::GetSwiftStdlibOSDir(const llvm::Triple &target,
10061006
return target.getOSName();
10071007
}
10081008

1009-
std::string SwiftASTContext::GetResourceDir(const llvm::Triple &triple) {
1009+
StringRef SwiftASTContext::GetResourceDir(const llvm::Triple &triple) {
10101010
static std::mutex g_mutex;
10111011
std::lock_guard<std::mutex> locker(g_mutex);
10121012
StringRef platform_sdk_path = GetPlatformSDKPath();
@@ -1706,7 +1706,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
17061706
}
17071707

17081708
triple = swift_ast_sp->GetTriple();
1709-
std::string resource_dir = swift_ast_sp->GetResourceDir(triple);
1709+
StringRef resource_dir = swift_ast_sp->GetResourceDir(triple);
17101710
ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(),
17111711
FileSpec(resource_dir), triple);
17121712

@@ -2014,7 +2014,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
20142014
}
20152015

20162016
llvm::Triple triple = swift_ast_sp->GetTriple();
2017-
std::string resource_dir = swift_ast_sp->GetResourceDir(triple);
2017+
StringRef resource_dir = swift_ast_sp->GetResourceDir(triple);
20182018
ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(),
20192019
FileSpec(resource_dir), triple);
20202020

@@ -2679,7 +2679,7 @@ void SwiftASTContext::InitializeSearchPathOptions(
26792679
}
26802680

26812681
llvm::Triple triple(GetTriple());
2682-
std::string resource_dir = GetResourceDir(triple);
2682+
StringRef resource_dir = GetResourceDir(triple);
26832683
ConfigureResourceDirs(GetCompilerInvocation(), FileSpec(resource_dir),
26842684
triple);
26852685

@@ -3437,7 +3437,7 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
34373437
// Compute the prebuilt module cache path to use:
34383438
// <resource-dir>/<platform>/prebuilt-modules
34393439
llvm::Triple triple(GetTriple());
3440-
llvm::SmallString<128> prebuiltModuleCachePath(GetResourceDir(triple));
3440+
llvm::SmallString<128> prebuiltModuleCachePath = GetResourceDir(triple);
34413441
StringRef platform;
34423442
if (swift::tripleIsMacCatalystEnvironment(triple)) {
34433443
// The prebuilt cache for macCatalyst is the same as the one for macOS,

lldb/unittests/Symbol/TestSwiftASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ struct SwiftASTContextTester : public SwiftASTContext {
7171
platform_sdk_path, swift_dir, swift_stdlib_os_dir, xcode_contents_path,
7272
toolchain_path, cl_tools_path);
7373
}
74-
static llvm::StringRef GetSwiftStdlibOSDir(const llvm::Triple &target,
75-
const llvm::Triple &host) {
74+
static std::string GetSwiftStdlibOSDir(const llvm::Triple &target,
75+
const llvm::Triple &host) {
7676
return SwiftASTContext::GetSwiftStdlibOSDir(target, host);
7777
}
7878
};

0 commit comments

Comments
 (0)