27 using namespace clang;
31 class ObjCContainersChecker :
public Checker< check::PreStmt<CallExpr>,
32 check::PostStmt<CallExpr>,
33 check::PointerEscape> {
34 mutable std::unique_ptr<BugType> BT;
35 inline void initBugType()
const {
37 BT.reset(
new BugType(
this,
"CFArray API",
47 void addSizeInfo(
const Expr *Array,
const Expr *Size,
52 static void *getTag() {
static int Tag;
return &Tag; }
66 void ObjCContainersChecker::addSizeInfo(const
Expr *Array, const
Expr *Size,
69 SVal SizeV = State->getSVal(Size, C.getLocationContext());
75 SVal ArrayRef = State->getSVal(Array, C.getLocationContext());
85 void ObjCContainersChecker::checkPostStmt(
const CallExpr *CE,
92 if (Name.equals(
"CFArrayCreate")) {
98 addSizeInfo(CE, CE->
getArg(2),
C);
102 if (Name.equals(
"CFArrayGetCount")) {
103 addSizeInfo(CE->
getArg(0), CE,
C);
108 void ObjCContainersChecker::checkPreStmt(
const CallExpr *CE,
115 if (Name.equals(
"CFArrayGetValueAtIndex")) {
121 SymbolRef ArraySym = getArraySym(ArrayExpr, C);
125 const DefinedSVal *Size = State->get<ArraySizeMap>(ArraySym);
140 ProgramStateRef StOutBound = State->assumeInBound(Idx, *Size,
false, T);
141 if (StOutBound && !StInBound) {
146 auto R = llvm::make_unique<BugReport>(*BT,
"Index is out of bounds", N);
147 R->addRange(IdxExpr->getSourceRange());
159 for (InvalidatedSymbols::const_iterator I = Escaped.begin(),
168 State = State->remove<ArraySizeMap>(Sym);
const char *const CoreFoundationObjectiveC
StringRef getCalleeName(const FunctionDecl *FunDecl) const
Get the name of the called function (path-sensitive).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Symbolic value. These values used to capture symbolic execution of the program.
bool isUnknownOrUndef() const
ExplodedNode * generateSink(ProgramStateRef State=nullptr, ExplodedNode *Pred=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a sink node. Generating a sink stops exploration of the given path.
const ProgramStateRef & getState() const
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
REGISTER_MAP_WITH_PROGRAMSTATE(AllocatedData, SymbolRef, MacOSKeychainAPIChecker::AllocationState) static bool isEnclosingFunctionParam(const Expr *E)
unsigned getNumArgs() const
Represents an abstract call to a function or method along a particular path.
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef. Otherwise, return 0.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
const LocationContext * getLocationContext() const