22 using namespace clang;
26 class ReturnPointerRangeChecker :
27 public Checker< check::PreStmt<ReturnStmt> > {
28 mutable std::unique_ptr<BuiltinBug> BT;
35 void ReturnPointerRangeChecker::checkPreStmt(
const ReturnStmt *RS,
62 ProgramStateRef StInBound = state->assumeInBound(Idx, NumElements,
true);
63 ProgramStateRef StOutBound = state->assumeInBound(Idx, NumElements,
false);
64 if (StOutBound && !StInBound) {
74 this,
"Return of pointer value outside of expected range",
75 "Returned pointer value points outside the original object "
76 "(potential buffer overflow)"));
83 auto report = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N);
85 report->addRange(RetE->getSourceRange());
90 void ento::registerReturnPointerRangeChecker(
CheckerManager &mgr) {
virtual DefinedOrUnknownSVal getSizeInElements(ProgramStateRef state, const MemRegion *region, QualType EleTy)
MemRegion - The root abstract class for all memory regions.
ExplodedNode * generateErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
bool isZeroConstant() const
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
const MemRegion * getSuperRegion() const
Expr - This represents one expression.
const ProgramStateRef & getState() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
StoreManager & getStoreManager()
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
const MemRegion * getAsRegion() const
const Expr * getRetValue() const
QualType getValueType() const override
ElementRegin is used to represent both array elements and casts.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
const LocationContext * getLocationContext() const