1 //== TaintTesterChecker.cpp ----------------------------------- -*- C++ -*--=//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This checker can be used for testing how taint data is propagated.
11 //===----------------------------------------------------------------------===//
14 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
15 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
16 #include "clang/StaticAnalyzer/Core/Checker.h"
17 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
20 using namespace clang;
22 using namespace taint;
25 class TaintTesterChecker : public Checker< check::PostStmt<Expr> > {
27 mutable std::unique_ptr<BugType> BT;
28 void initBugType() const;
30 /// Given a pointer argument, get the symbol of the value it contains
32 SymbolRef getPointedToSymbol(CheckerContext &C,
34 bool IssueWarning = true) const;
37 void checkPostStmt(const Expr *E, CheckerContext &C) const;
41 inline void TaintTesterChecker::initBugType() const {
43 BT.reset(new BugType(this, "Tainted data", "General"));
46 void TaintTesterChecker::checkPostStmt(const Expr *E,
47 CheckerContext &C) const {
48 ProgramStateRef State = C.getState();
52 if (isTainted(State, E, C.getLocationContext())) {
53 if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
55 auto report = std::make_unique<PathSensitiveBugReport>(*BT, "tainted", N);
56 report->addRange(E->getSourceRange());
57 C.emitReport(std::move(report));
62 void ento::registerTaintTesterChecker(CheckerManager &mgr) {
63 mgr.registerChecker<TaintTesterChecker>();
66 bool ento::shouldRegisterTaintTesterChecker(const LangOptions &LO) {