Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/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 "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
14
#include "clang/StaticAnalyzer/Checkers/Taint.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
  std::unique_ptr<BugType> BT =
27
      std::make_unique<BugType>(this, "Tainted data", "General");
28
29
public:
30
  void checkPostStmt(const Expr *E, CheckerContext &C) const;
31
};
32
}
33
34
void TaintTesterChecker::checkPostStmt(const Expr *E,
35
1.00k
                                       CheckerContext &C) const {
36
1.00k
  ProgramStateRef State = C.getState();
37
1.00k
  if (!State)
38
0
    return;
39
40
1.00k
  if (isTainted(State, E, C.getLocationContext())) {
41
109
    if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
42
109
      auto report = std::make_unique<PathSensitiveBugReport>(*BT, "tainted", N);
43
109
      report->addRange(E->getSourceRange());
44
109
      C.emitReport(std::move(report));
45
109
    }
46
109
  }
47
1.00k
}
48
49
8
void ento::registerTaintTesterChecker(CheckerManager &mgr) {
50
8
  mgr.registerChecker<TaintTesterChecker>();
51
8
}
52
53
16
bool ento::shouldRegisterTaintTesterChecker(const CheckerManager &mgr) {
54
16
  return true;
55
16
}