Skip to content

Commit 8303289

Browse files
committed
[sourcekit] Fix use-after-free of request string
The CursorInfoConsumer outlives the request call, so we need to copy the input filename string. This fixes a use-after-free elucidated by asan.
1 parent 8c42386 commit 8303289

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ class CursorRangeInfoConsumer : public SwiftASTConsumer {
11621162
protected:
11631163
SwiftLangSupport ⟪
11641164
SwiftInvocationRef ASTInvok;
1165-
StringRef InputFile;
1165+
std::string InputFile;
11661166
unsigned Offset;
11671167
unsigned Length;
11681168

@@ -1181,7 +1181,7 @@ class CursorRangeInfoConsumer : public SwiftASTConsumer {
11811181
CursorRangeInfoConsumer(StringRef InputFile, unsigned Offset, unsigned Length,
11821182
SwiftLangSupport &Lang, SwiftInvocationRef ASTInvok,
11831183
bool TryExistingAST, bool CancelOnSubsequentRequest)
1184-
: Lang(Lang), ASTInvok(ASTInvok),InputFile(InputFile), Offset(Offset),
1184+
: Lang(Lang), ASTInvok(ASTInvok),InputFile(InputFile.str()), Offset(Offset),
11851185
Length(Length), TryExistingAST(TryExistingAST),
11861186
CancelOnSubsequentRequest(CancelOnSubsequentRequest) {}
11871187

0 commit comments

Comments
 (0)