28class DivZeroChecker :
public Checker<check::PreStmt<BinaryOperator>> {
37 enum CheckKind { CK_DivideZero, CK_TaintedDivChecker, CK_NumCheckKinds };
38 bool ChecksEnabled[CK_NumCheckKinds] = {
false};
40 mutable std::unique_ptr<BugType> BugTypes[CK_NumCheckKinds];
48 if (
const auto *BE = dyn_cast<BinaryOperator>(S))
55 if (!ChecksEnabled[CK_DivideZero])
57 if (!BugTypes[CK_DivideZero])
58 BugTypes[CK_DivideZero].reset(
59 new BugType(CheckNames[CK_DivideZero],
"Division by zero"));
61 auto R = std::make_unique<PathSensitiveBugReport>(*BugTypes[CK_DivideZero],
64 C.emitReport(std::move(R));
68void DivZeroChecker::reportTaintBug(
71 if (!ChecksEnabled[CK_TaintedDivChecker])
73 if (!BugTypes[CK_TaintedDivChecker])
74 BugTypes[CK_TaintedDivChecker].reset(
75 new BugType(CheckNames[CK_TaintedDivChecker],
"Division by zero",
77 if (
ExplodedNode *N =
C.generateNonFatalErrorNode(StateZero)) {
78 auto R = std::make_unique<PathSensitiveBugReport>(
79 *BugTypes[CK_TaintedDivChecker], Msg, N);
81 for (
auto Sym : TaintedSyms)
82 R->markInteresting(Sym);
83 C.emitReport(std::move(R));
110 std::tie(stateNotZero, stateZero) = CM.
assumeDual(
C.getState(), *DV);
114 reportBug(
"Division by zero", stateZero,
C);
118 if ((stateNotZero && stateZero)) {
120 if (!taintedSyms.empty()) {
121 reportTaintBug(
"Division by a tainted value, possibly zero", stateNotZero,
129 C.addTransition(stateNotZero);
134 checker->ChecksEnabled[DivZeroChecker::CK_DivideZero] =
true;
135 checker->CheckNames[DivZeroChecker::CK_DivideZero] =
139bool ento::shouldRegisterDivZeroChecker(
const CheckerManager &mgr) {
144 DivZeroChecker *checker;
149 checker->ChecksEnabled[DivZeroChecker::CK_TaintedDivChecker] =
true;
150 checker->CheckNames[DivZeroChecker::CK_TaintedDivChecker] =
154bool ento::shouldRegisterTaintedDivChecker(
const CheckerManager &mgr) {
static const Expr * getDenomExpr(const ExplodedNode *N)
A builtin binary operation expression such as "x + y" or "x <= y".
This represents one expression.
Stmt - This represents one statement.
bool isScalarType() const
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
CheckerNameRef getCurrentCheckerName() const
bool isRegisteredChecker()
This wrapper is used to ensure that only StringRefs originating from the CheckerRegistry are used as ...
ProgramStatePair assumeDual(ProgramStateRef State, DefinedSVal Cond)
Returns a pair of states (StTrue, StFalse) where the given condition is assumed to be true or false,...
std::optional< T > getLocationAs() const &
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
bool trackExpressionValue(const ExplodedNode *N, const Expr *E, PathSensitiveBugReport &R, TrackingOptions Opts={})
Attempts to add visitors to track expression value back to its point of origin.
const char *const TaintedData
std::vector< SymbolRef > getTaintedSymbols(ProgramStateRef State, const Stmt *S, const LocationContext *LCtx, TaintTagType Kind=TaintTagGeneric)
Returns the tainted Symbols for a given Statement and state.
The JSON file list parser is used to communicate input to InstallAPI.