22 using namespace clang;
26 class ArrayBoundChecker :
27 public Checker<check::Location> {
28 mutable std::unique_ptr<BuiltinBug> BT;
31 void checkLocation(SVal l,
bool isLoad,
const Stmt* S,
32 CheckerContext &C)
const;
36 void ArrayBoundChecker::checkLocation(SVal l,
bool isLoad,
const Stmt* LoadS,
37 CheckerContext &C)
const {
39 const MemRegion *R = l.getAsRegion();
43 const ElementRegion *ER = dyn_cast<ElementRegion>(R);
48 DefinedOrUnknownSVal Idx = ER->getIndex().castAs<DefinedOrUnknownSVal>();
52 if (Idx.isZeroConstant())
58 DefinedOrUnknownSVal NumElements
59 = C.getStoreManager().getSizeInElements(state, ER->getSuperRegion(),
62 ProgramStateRef StInBound = state->assumeInBound(Idx, NumElements,
true);
63 ProgramStateRef StOutBound = state->assumeInBound(Idx, NumElements,
false);
64 if (StOutBound && !StInBound) {
65 ExplodedNode *N = C.generateErrorNode(StOutBound);
70 BT.reset(
new BuiltinBug(
71 this,
"Out-of-bound array access",
72 "Access out-of-bound array element (buffer overflow)"));
79 auto report = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N);
82 C.emitReport(std::move(report));
88 C.addTransition(StInBound);
91 void ento::registerArrayBoundChecker(CheckerManager &mgr) {
92 mgr.registerChecker<ArrayBoundChecker>();
Stmt - This represents one statement.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
Dataflow Directional Tag Classes.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...