Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp
Line
Count
Source (jump to first uncovered line)
1
//== TaintTesterChecker.cpp ----------------------------------- -*- C++ -*--=//
2
//
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
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This checker can be used for testing how taint data is propagated.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "Taint.h"
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"
19
20
using namespace clang;
21
using namespace ento;
22
using namespace taint;
23
24
namespace {
25
class TaintTesterChecker : public Checker< check::PostStmt<Expr> > {
26
27
  mutable std::unique_ptr<BugType> BT;
28
  void initBugType() const;
29
30
  /// Given a pointer argument, get the symbol of the value it contains
31
  /// (points to).
32
  SymbolRef getPointedToSymbol(CheckerContext &C,
33
                               const Expr* Arg,
34
                               bool IssueWarning = true) const;
35
36
public:
37
  void checkPostStmt(const Expr *E, CheckerContext &C) const;
38
};
39
}
40
41
106
inline void TaintTesterChecker::initBugType() const {
42
106
  if (!BT)
43
4
    BT.reset(new BugType(this, "Tainted data", "General"));
44
106
}
45
46
void TaintTesterChecker::checkPostStmt(const Expr *E,
47
1.02k
                                       CheckerContext &C) const {
48
1.02k
  ProgramStateRef State = C.getState();
49
1.02k
  if (!State)
50
0
    return;
51
1.02k
52
1.02k
  if (isTainted(State, E, C.getLocationContext())) {
53
106
    if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
54
106
      initBugType();
55
106
      auto report = llvm::make_unique<BugReport>(*BT, "tainted",N);
56
106
      report->addRange(E->getSourceRange());
57
106
      C.emitReport(std::move(report));
58
106
    }
59
106
  }
60
1.02k
}
61
62
6
void ento::registerTaintTesterChecker(CheckerManager &mgr) {
63
6
  mgr.registerChecker<TaintTesterChecker>();
64
6
}
65
66
6
bool ento::shouldRegisterTaintTesterChecker(const LangOptions &LO) {
67
6
  return true;
68
6
}