aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2019-01-08 16:55:13 +0000
committerAlexander Kornienko <alexfh@google.com>2019-01-08 16:55:13 +0000
commit3957586ddbbd230dc6dcff6f187f11f013ab827d (patch)
tree9dd7edf46012795ed25fef95e9620fe1819fdbd6 /unittests
parent24b21ed3f748f679552f56ffe65914d0108d4eca (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350638 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Analysis/ExprMutationAnalyzerTest.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/unittests/Analysis/ExprMutationAnalyzerTest.cpp b/unittests/Analysis/ExprMutationAnalyzerTest.cpp
index 9c6bc783b3..68c921e439 100644
--- a/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ b/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;
}