33 TaintMapTy TM = State->get<TaintMap>();
36 Out <<
"Tainted symbols:" << NL;
38 for (
const auto &I : TM)
39 Out << I.first <<
" : " << I.second << NL;
49 return addTaint(State, State->getSVal(E, LCtx), Kind);
68 if (std::optional<SVal> binding =
69 State->getStateManager().getStoreManager().getDefaultBinding(
71 if (
SymbolRef Sym = binding->getAsSymbol())
82 if (
const SymbolicRegion *SR = dyn_cast_or_null<SymbolicRegion>(R))
83 return addTaint(State, SR->getSymbol(), Kind);
91 while (
const SymbolCast *SC = dyn_cast<SymbolCast>(Sym))
92 Sym = SC->getOperand();
109 if (
const SymbolicRegion *SR = dyn_cast_or_null<SymbolicRegion>(R))
117 while (
const SymbolCast *SC = dyn_cast<SymbolCast>(Sym))
118 Sym = SC->getOperand();
130 if (
const TaintTagType *T = State->get<TaintMap>(ParentSym))
136 return addTaint(State, ParentSym, Kind);
138 const TaintedSubRegions *SavedRegs = State->get<DerivedSymTaint>(ParentSym);
139 TaintedSubRegions::Factory &F = State->get_context<TaintedSubRegions>();
140 TaintedSubRegions Regs = SavedRegs ? *SavedRegs : F.getEmptyMap();
143 ProgramStateRef NewState = State->set<DerivedSymTaint>(ParentSym, Regs);
199 bool returnFirstOnly) {
200 SVal val = State->getSVal(E, LCtx);
206 bool returnFirstOnly) {
213 StoreManager &StoreMgr = State->getStateManager().getStoreManager();
225 bool returnFirstOnly) {
226 std::vector<SymbolRef> TaintedSymbols;
228 return TaintedSymbols;
231 if (
const ElementRegion *ER = dyn_cast<ElementRegion>(Reg)) {
232 std::vector<SymbolRef> TaintedIndex =
234 llvm::append_range(TaintedSymbols, TaintedIndex);
235 if (returnFirstOnly && !TaintedSymbols.empty())
236 return TaintedSymbols;
241 std::vector<SymbolRef> TaintedRegions =
243 llvm::append_range(TaintedSymbols, TaintedRegions);
244 if (returnFirstOnly && !TaintedSymbols.empty())
245 return TaintedSymbols;
250 if (
const SubRegion *ER = dyn_cast<SubRegion>(Reg)) {
251 std::vector<SymbolRef> TaintedSubRegions =
253 llvm::append_range(TaintedSymbols, TaintedSubRegions);
254 if (returnFirstOnly && !TaintedSymbols.empty())
255 return TaintedSymbols;
258 return TaintedSymbols;
264 bool returnFirstOnly) {
265 std::vector<SymbolRef> TaintedSymbols;
267 return TaintedSymbols;
270 if (
const auto &Opts = State->getAnalysisManager().getAnalyzerOptions();
280 if (
const TaintTagType *Tag = State->get<TaintMap>(SubSym)) {
282 TaintedSymbols.push_back(SubSym);
284 return TaintedSymbols;
288 if (
const auto *SD = dyn_cast<SymbolDerived>(SubSym)) {
291 State, SD->getParentSymbol(), Kind, returnFirstOnly);
292 llvm::append_range(TaintedSymbols, TaintedParents);
293 if (returnFirstOnly && !TaintedSymbols.empty())
294 return TaintedSymbols;
299 if (
const TaintedSubRegions *Regs =
300 State->get<DerivedSymTaint>(SD->getParentSymbol())) {
302 for (
auto I : *Regs) {
307 if (Kind == I.second && R->isSubRegionOf(I.first)) {
308 TaintedSymbols.push_back(SD->getParentSymbol());
309 if (returnFirstOnly && !TaintedSymbols.empty())
310 return TaintedSymbols;
317 if (
const auto *SRV = dyn_cast<SymbolRegionValue>(SubSym)) {
318 std::vector<SymbolRef> TaintedRegions =
320 llvm::append_range(TaintedSymbols, TaintedRegions);
321 if (returnFirstOnly && !TaintedSymbols.empty())
322 return TaintedSymbols;
326 if (
const auto *SC = dyn_cast<SymbolCast>(SubSym)) {
327 std::vector<SymbolRef> TaintedCasts =
329 llvm::append_range(TaintedSymbols, TaintedCasts);
330 if (returnFirstOnly && !TaintedSymbols.empty())
331 return TaintedSymbols;
334 return TaintedSymbols;
#define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value)
Declares an immutable map of type NameTy, suitable for placement into the ProgramState.
#define REGISTER_MAP_FACTORY_WITH_PROGRAMSTATE(Name, Key, Value)
Declares an immutable map type Name and registers the factory for such maps in the program state,...
This represents one expression.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
ElementRegion is used to represent both array elements and casts.
MemRegion - The root abstract class for all memory regions.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getBaseRegion() const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
virtual std::optional< SVal > getDefaultBinding(Store store, const MemRegion *R)=0
Return the default value bound to a region in a given store.
SubRegion - A region that subsets another larger region.
llvm::iterator_range< symbol_iterator > symbols() const
virtual unsigned computeComplexity() const =0
Represents a cast expression.
SymbolicRegion - A special, "non-concrete" region.
TypedValueRegion - An abstract class representing regions having a typed value.
While nonloc::CompoundVal covers a few simple use cases, nonloc::LazyCompoundVal is a more performant...
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.
ProgramStateRef removeTaint(ProgramStateRef State, SVal V)
std::vector< SymbolRef > getTaintedSymbolsImpl(ProgramStateRef State, const Expr *E, const LocationContext *LCtx, TaintTagType Kind, bool returnFirstOnly)
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.
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.
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.
LLVM_DUMP_METHOD void dumpTaint(ProgramStateRef State)
unsigned TaintTagType
The type of taint, which helps to differentiate between different types of taint.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const SymExpr * SymbolRef
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
for(const auto &A :T->param_types())