clang 23.0.0git
Taint.h
Go to the documentation of this file.
1//=== Taint.h - Taint tracking and basic propagation rules. --------*- 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// Defines basic, non-domain-specific mechanisms for tracking tainted values.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_TAINT_H
14#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_TAINT_H
15
18
19namespace clang {
20namespace ento {
21namespace taint {
22
23/// The type of taint, which helps to differentiate between different types of
24/// taint.
26
27static constexpr TaintTagType TaintTagGeneric = 0;
28
29/// Create a new state in which the value of the expression is marked as
30/// tainted.
31[[nodiscard]] ProgramStateRef addTaint(ProgramStateRef State, const Expr *E,
32 const LocationContext *LCtx,
34
35/// Create a new state in which the value is marked as tainted.
36[[nodiscard]] ProgramStateRef addTaint(ProgramStateRef State, SVal V,
38
39/// Create a new state in which the symbol is marked as tainted.
40[[nodiscard]] ProgramStateRef addTaint(ProgramStateRef State, SymbolRef Sym,
42
43/// Create a new state in which the pointer represented by the region
44/// is marked as tainted.
45[[nodiscard]] ProgramStateRef addTaint(ProgramStateRef State,
46 const MemRegion *R,
48
50
52 const MemRegion *R);
53
55
56/// Create a new state in a which a sub-region of a given symbol is tainted.
57/// This might be necessary when referring to regions that can not have an
58/// individual symbol, e.g. if they are represented by the default binding of
59/// a LazyCompoundVal.
60[[nodiscard]] ProgramStateRef
62 const SubRegion *SubRegion,
64
65/// Check if the expression has a tainted value in the given state.
66bool isTainted(ProgramStateRef State, const Expr *E,
67 const LocationContext *LCtx,
69
70/// Check if the value is tainted in the given state.
73
74/// Check if the symbol is tainted in the given state.
75bool isTainted(ProgramStateRef State, SymbolRef Sym,
77
78/// Check if the pointer represented by the region is tainted in the given
79/// state.
80bool isTainted(ProgramStateRef State, const MemRegion *Reg,
82
83/// Returns the tainted Symbols for a given expression and state.
84std::vector<SymbolRef> getTaintedSymbols(ProgramStateRef State, const Expr *E,
85 const LocationContext *LCtx,
87
88/// Returns the tainted Symbols for a given SVal and state.
89std::vector<SymbolRef> getTaintedSymbols(ProgramStateRef State, SVal V,
91
92/// Returns the tainted Symbols for a SymbolRef and state.
93std::vector<SymbolRef> getTaintedSymbols(ProgramStateRef State, SymbolRef Sym,
95
96/// Returns the tainted (index, super/sub region, symbolic region) symbols
97/// for a given memory region.
98std::vector<SymbolRef> getTaintedSymbols(ProgramStateRef State,
99 const MemRegion *Reg,
101
102std::vector<SymbolRef> getTaintedSymbolsImpl(ProgramStateRef State,
103 const Expr *E,
104 const LocationContext *LCtx,
105 TaintTagType Kind,
106 bool returnFirstOnly);
107
108std::vector<SymbolRef> getTaintedSymbolsImpl(ProgramStateRef State, SVal V,
109 TaintTagType Kind,
110 bool returnFirstOnly);
111
112std::vector<SymbolRef> getTaintedSymbolsImpl(ProgramStateRef State,
113 SymbolRef Sym, TaintTagType Kind,
114 bool returnFirstOnly);
115
116std::vector<SymbolRef> getTaintedSymbolsImpl(ProgramStateRef State,
117 const MemRegion *Reg,
118 TaintTagType Kind,
119 bool returnFirstOnly);
120
121void printTaint(ProgramStateRef State, raw_ostream &Out, const char *nl = "\n",
122 const char *sep = "");
123
124LLVM_DUMP_METHOD void dumpTaint(ProgramStateRef State);
125} // namespace taint
126} // namespace ento
127} // namespace clang
128
129#endif
#define V(N, I)
This represents one expression.
Definition Expr.h:112
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
MemRegion - The root abstract class for all memory regions.
Definition MemRegion.h:98
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition SVals.h:56
SubRegion - A region that subsets another larger region.
Definition MemRegion.h:474
std::vector< SymbolRef > getTaintedSymbols(ProgramStateRef State, const Expr *E, const LocationContext *LCtx, TaintTagType Kind=TaintTagGeneric)
Returns the tainted Symbols for a given expression and state.
Definition Taint.cpp:170
ProgramStateRef removeTaint(ProgramStateRef State, SVal V)
Definition Taint.cpp:99
std::vector< SymbolRef > getTaintedSymbolsImpl(ProgramStateRef State, const Expr *E, const LocationContext *LCtx, TaintTagType Kind, bool returnFirstOnly)
Definition Taint.cpp:195
void printTaint(ProgramStateRef State, raw_ostream &Out, const char *nl="\n", const char *sep="")
ProgramStateRef addTaint(ProgramStateRef State, const Expr *E, const LocationContext *LCtx, TaintTagType Kind=TaintTagGeneric)
Create a new state in which the value of the expression is marked as tainted.
Definition Taint.cpp:46
ProgramStateRef addPartialTaint(ProgramStateRef State, SymbolRef ParentSym, const SubRegion *SubRegion, TaintTagType Kind=TaintTagGeneric)
Create a new state in a which a sub-region of a given symbol is tainted.
Definition Taint.cpp:125
bool isTainted(ProgramStateRef State, const Expr *E, const LocationContext *LCtx, TaintTagType Kind=TaintTagGeneric)
Check if the expression has a tainted value in the given state.
Definition Taint.cpp:148
LLVM_DUMP_METHOD void dumpTaint(ProgramStateRef State)
Definition Taint.cpp:42
unsigned TaintTagType
The type of taint, which helps to differentiate between different types of taint.
Definition Taint.h:25
static constexpr TaintTagType TaintTagGeneric
Definition Taint.h:27
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const SymExpr * SymbolRef
Definition SymExpr.h:133
The JSON file list parser is used to communicate input to InstallAPI.