diff options
author | Alexander Kornienko <alexfh@google.com> | 2019-01-08 16:55:13 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2019-01-08 16:55:13 +0000 |
commit | 973fcc25fb19b9bcd845a8f260673319b12954a5 (patch) | |
tree | b4cbde2dea1c40c4a37ee112c503a24d406e76f9 /clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp | |
parent | 0d99031de0306b2ab1a21e2cd8b599acf796b6b4 (diff) | |
download | bcm5719-llvm-973fcc25fb19b9bcd845a8f260673319b12954a5.tar.gz bcm5719-llvm-973fcc25fb19b9bcd845a8f260673319b12954a5.zip |
Fix use-after-free bug in Tooling.
Summary:
`buildASTFromCodeWithArgs()` was creating a memory buffer referencing a
stack-allocated string. This diff changes the implementation to copy the code
string into the memory buffer so that said buffer owns the memory.
Patch by Yitzhak Mandelbaum.
Reviewers: alexfh
Reviewed By: alexfh
Subscribers: cfe-commits, EricWF
Differential Revision: https://reviews.llvm.org/D55765
llvm-svn: 350638
Diffstat (limited to 'clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp')
-rw-r--r-- | clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp index 9c6bc783b33..68c921e4398 100644 --- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp +++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp @@ -11,6 +11,7 @@ #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/SmallString.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include <cctype> @@ -32,7 +33,9 @@ using StmtMatcher = internal::Matcher<Stmt>; std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(const Twine &Code, const std::vector<std::string> &Args) { - auto AST = tooling::buildASTFromCodeWithArgs(Code, Args); + SmallString<1024> CodeStorage; + auto AST = + tooling::buildASTFromCodeWithArgs(Code.toStringRef(CodeStorage), Args); EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred()); return AST; } |