Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 1 | //= CStringChecker.h - Checks calls to C string functions ----------*- C++ -*-// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This defines CStringChecker, which is an assortment of checks on calls |
| 11 | // to functions in <string.h>. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Argyrios Kyrtzidis | a0decc9 | 2011-02-15 21:25:03 +0000 | [diff] [blame] | 15 | #include "ClangSACheckers.h" |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 16 | #include "clang/StaticAnalyzer/Core/CheckerV2.h" |
Argyrios Kyrtzidis | 695fb50 | 2011-02-17 21:39:17 +0000 | [diff] [blame] | 17 | #include "clang/StaticAnalyzer/Core/CheckerManager.h" |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 18 | #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" |
Ted Kremenek | 9b66371 | 2011-02-10 01:03:03 +0000 | [diff] [blame] | 19 | #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" |
Ted Kremenek | 9b66371 | 2011-02-10 01:03:03 +0000 | [diff] [blame] | 20 | #include "clang/StaticAnalyzer/Core/PathSensitive/GRStateTrait.h" |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringSwitch.h" |
| 22 | |
| 23 | using namespace clang; |
Ted Kremenek | 9ef6537 | 2010-12-23 07:20:52 +0000 | [diff] [blame] | 24 | using namespace ento; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 25 | |
| 26 | namespace { |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 27 | class CStringChecker : public CheckerV2< eval::Call, |
| 28 | check::PreStmt<DeclStmt>, |
| 29 | check::LiveSymbols, |
| 30 | check::DeadSymbols, |
| 31 | check::RegionChanges |
| 32 | > { |
| 33 | mutable llvm::OwningPtr<BugType> BT_Null, BT_Bounds, BT_BoundsWrite, |
| 34 | BT_Overlap, BT_NotCString; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 35 | public: |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 36 | static void *getTag() { static int tag; return &tag; } |
| 37 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 38 | bool evalCall(const CallExpr *CE, CheckerContext &C) const; |
| 39 | void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const; |
| 40 | void checkLiveSymbols(const GRState *state, SymbolReaper &SR) const; |
| 41 | void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const; |
| 42 | bool wantsRegionChangeUpdate(const GRState *state) const; |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 43 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 44 | const GRState *checkRegionChanges(const GRState *state, |
| 45 | const MemRegion * const *Begin, |
| 46 | const MemRegion * const *End) const; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 47 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 48 | typedef void (CStringChecker::*FnCheck)(CheckerContext &, |
| 49 | const CallExpr *) const; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 50 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 51 | void evalMemcpy(CheckerContext &C, const CallExpr *CE) const; |
| 52 | void evalMemmove(CheckerContext &C, const CallExpr *CE) const; |
| 53 | void evalBcopy(CheckerContext &C, const CallExpr *CE) const; |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 54 | void evalCopyCommon(CheckerContext &C, const GRState *state, |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 55 | const Expr *Size, const Expr *Source, const Expr *Dest, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 56 | bool Restricted = false) const; |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 57 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 58 | void evalMemcmp(CheckerContext &C, const CallExpr *CE) const; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 59 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 60 | void evalstrLength(CheckerContext &C, const CallExpr *CE) const; |
| 61 | void evalstrnLength(CheckerContext &C, const CallExpr *CE) const; |
Ted Kremenek | be4242c | 2011-02-22 04:55:05 +0000 | [diff] [blame] | 62 | void evalstrLengthCommon(CheckerContext &C, const CallExpr *CE, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 63 | bool IsStrnlen = false) const; |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 64 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 65 | void evalStrcpy(CheckerContext &C, const CallExpr *CE) const; |
| 66 | void evalStrncpy(CheckerContext &C, const CallExpr *CE) const; |
| 67 | void evalStpcpy(CheckerContext &C, const CallExpr *CE) const; |
Ted Kremenek | 0ef473f | 2011-02-22 04:58:34 +0000 | [diff] [blame] | 68 | void evalStrcpyCommon(CheckerContext &C, const CallExpr *CE, bool returnEnd, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 69 | bool isStrncpy) const; |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 70 | |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 71 | // Utility methods |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 72 | std::pair<const GRState*, const GRState*> |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 73 | static assumeZero(CheckerContext &C, |
| 74 | const GRState *state, SVal V, QualType Ty); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 75 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 76 | static const GRState *setCStringLength(const GRState *state, |
| 77 | const MemRegion *MR, SVal strLength); |
| 78 | static SVal getCStringLengthForRegion(CheckerContext &C, |
| 79 | const GRState *&state, |
| 80 | const Expr *Ex, const MemRegion *MR); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 81 | SVal getCStringLength(CheckerContext &C, const GRState *&state, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 82 | const Expr *Ex, SVal Buf) const; |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 83 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 84 | static const GRState *InvalidateBuffer(CheckerContext &C, |
| 85 | const GRState *state, |
| 86 | const Expr *Ex, SVal V); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 87 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 88 | static bool SummarizeRegion(llvm::raw_ostream& os, ASTContext& Ctx, |
| 89 | const MemRegion *MR); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 90 | |
| 91 | // Re-usable checks |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 92 | const GRState *checkNonNull(CheckerContext &C, const GRState *state, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 93 | const Expr *S, SVal l) const; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 94 | const GRState *CheckLocation(CheckerContext &C, const GRState *state, |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 95 | const Expr *S, SVal l, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 96 | bool IsDestination = false) const; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 97 | const GRState *CheckBufferAccess(CheckerContext &C, const GRState *state, |
| 98 | const Expr *Size, |
| 99 | const Expr *FirstBuf, |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 100 | const Expr *SecondBuf = NULL, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 101 | bool FirstIsDestination = false) const; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 102 | const GRState *CheckOverlap(CheckerContext &C, const GRState *state, |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 103 | const Expr *Size, const Expr *First, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 104 | const Expr *Second) const; |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 105 | void emitOverlapBug(CheckerContext &C, const GRState *state, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 106 | const Stmt *First, const Stmt *Second) const; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 107 | }; |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 108 | |
| 109 | class CStringLength { |
| 110 | public: |
| 111 | typedef llvm::ImmutableMap<const MemRegion *, SVal> EntryMap; |
| 112 | }; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 113 | } //end anonymous namespace |
| 114 | |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 115 | namespace clang { |
Ted Kremenek | 9ef6537 | 2010-12-23 07:20:52 +0000 | [diff] [blame] | 116 | namespace ento { |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 117 | template <> |
| 118 | struct GRStateTrait<CStringLength> |
| 119 | : public GRStatePartialTrait<CStringLength::EntryMap> { |
| 120 | static void *GDMIndex() { return CStringChecker::getTag(); } |
| 121 | }; |
| 122 | } |
Argyrios Kyrtzidis | 5a4f98f | 2010-12-22 18:53:20 +0000 | [diff] [blame] | 123 | } |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 124 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 125 | //===----------------------------------------------------------------------===// |
| 126 | // Individual checks and utility methods. |
| 127 | //===----------------------------------------------------------------------===// |
| 128 | |
| 129 | std::pair<const GRState*, const GRState*> |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 130 | CStringChecker::assumeZero(CheckerContext &C, const GRState *state, SVal V, |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 131 | QualType Ty) { |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 132 | DefinedSVal *val = dyn_cast<DefinedSVal>(&V); |
| 133 | if (!val) |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 134 | return std::pair<const GRState*, const GRState *>(state, state); |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 135 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 136 | SValBuilder &svalBuilder = C.getSValBuilder(); |
| 137 | DefinedOrUnknownSVal zero = svalBuilder.makeZeroVal(Ty); |
| 138 | return state->assume(svalBuilder.evalEQ(state, *val, zero)); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 139 | } |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 140 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 141 | const GRState *CStringChecker::checkNonNull(CheckerContext &C, |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 142 | const GRState *state, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 143 | const Expr *S, SVal l) const { |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 144 | // If a previous check has failed, propagate the failure. |
| 145 | if (!state) |
| 146 | return NULL; |
| 147 | |
| 148 | const GRState *stateNull, *stateNonNull; |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 149 | llvm::tie(stateNull, stateNonNull) = assumeZero(C, state, l, S->getType()); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 150 | |
| 151 | if (stateNull && !stateNonNull) { |
Ted Kremenek | d048c6e | 2010-12-20 21:19:09 +0000 | [diff] [blame] | 152 | ExplodedNode *N = C.generateSink(stateNull); |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 153 | if (!N) |
| 154 | return NULL; |
| 155 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 156 | if (!BT_Null) |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 157 | BT_Null.reset(new BuiltinBug("API", |
| 158 | "Null pointer argument in call to byte string function")); |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 159 | |
| 160 | // Generate a report for this bug. |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 161 | BuiltinBug *BT = static_cast<BuiltinBug*>(BT_Null.get()); |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 162 | EnhancedBugReport *report = new EnhancedBugReport(*BT, |
| 163 | BT->getDescription(), N); |
| 164 | |
| 165 | report->addRange(S->getSourceRange()); |
| 166 | report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, S); |
| 167 | C.EmitReport(report); |
| 168 | return NULL; |
| 169 | } |
| 170 | |
| 171 | // From here on, assume that the value is non-null. |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 172 | assert(stateNonNull); |
| 173 | return stateNonNull; |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 176 | // FIXME: This was originally copied from ArrayBoundChecker.cpp. Refactor? |
| 177 | const GRState *CStringChecker::CheckLocation(CheckerContext &C, |
| 178 | const GRState *state, |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 179 | const Expr *S, SVal l, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 180 | bool IsDestination) const { |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 181 | // If a previous check has failed, propagate the failure. |
| 182 | if (!state) |
| 183 | return NULL; |
| 184 | |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 185 | // Check for out of bound array element access. |
| 186 | const MemRegion *R = l.getAsRegion(); |
| 187 | if (!R) |
| 188 | return state; |
| 189 | |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 190 | const ElementRegion *ER = dyn_cast<ElementRegion>(R); |
| 191 | if (!ER) |
| 192 | return state; |
| 193 | |
Zhongxing Xu | 018220c | 2010-08-11 06:10:55 +0000 | [diff] [blame] | 194 | assert(ER->getValueType() == C.getASTContext().CharTy && |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 195 | "CheckLocation should only be called with char* ElementRegions"); |
| 196 | |
| 197 | // Get the size of the array. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 198 | const SubRegion *superReg = cast<SubRegion>(ER->getSuperRegion()); |
| 199 | SValBuilder &svalBuilder = C.getSValBuilder(); |
| 200 | SVal Extent = svalBuilder.convertToArrayIndex(superReg->getExtent(svalBuilder)); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 201 | DefinedOrUnknownSVal Size = cast<DefinedOrUnknownSVal>(Extent); |
| 202 | |
| 203 | // Get the index of the accessed element. |
Gabor Greif | 89b0658 | 2010-09-09 10:51:37 +0000 | [diff] [blame] | 204 | DefinedOrUnknownSVal Idx = cast<DefinedOrUnknownSVal>(ER->getIndex()); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 205 | |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 206 | const GRState *StInBound = state->assumeInBound(Idx, Size, true); |
| 207 | const GRState *StOutBound = state->assumeInBound(Idx, Size, false); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 208 | if (StOutBound && !StInBound) { |
Ted Kremenek | d048c6e | 2010-12-20 21:19:09 +0000 | [diff] [blame] | 209 | ExplodedNode *N = C.generateSink(StOutBound); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 210 | if (!N) |
| 211 | return NULL; |
| 212 | |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 213 | BuiltinBug *BT; |
| 214 | if (IsDestination) { |
| 215 | if (!BT_BoundsWrite) { |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 216 | BT_BoundsWrite.reset(new BuiltinBug("Out-of-bound array access", |
| 217 | "Byte string function overflows destination buffer")); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 218 | } |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 219 | BT = static_cast<BuiltinBug*>(BT_BoundsWrite.get()); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 220 | } else { |
| 221 | if (!BT_Bounds) { |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 222 | BT_Bounds.reset(new BuiltinBug("Out-of-bound array access", |
| 223 | "Byte string function accesses out-of-bound array element")); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 224 | } |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 225 | BT = static_cast<BuiltinBug*>(BT_Bounds.get()); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 226 | } |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 227 | |
| 228 | // FIXME: It would be nice to eventually make this diagnostic more clear, |
| 229 | // e.g., by referencing the original declaration or by saying *why* this |
| 230 | // reference is outside the range. |
| 231 | |
| 232 | // Generate a report for this bug. |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 233 | RangedBugReport *report = new RangedBugReport(*BT, BT->getDescription(), N); |
| 234 | |
| 235 | report->addRange(S->getSourceRange()); |
| 236 | C.EmitReport(report); |
| 237 | return NULL; |
| 238 | } |
| 239 | |
| 240 | // Array bound check succeeded. From this point forward the array bound |
| 241 | // should always succeed. |
| 242 | return StInBound; |
| 243 | } |
| 244 | |
| 245 | const GRState *CStringChecker::CheckBufferAccess(CheckerContext &C, |
| 246 | const GRState *state, |
| 247 | const Expr *Size, |
| 248 | const Expr *FirstBuf, |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 249 | const Expr *SecondBuf, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 250 | bool FirstIsDestination) const { |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 251 | // If a previous check has failed, propagate the failure. |
| 252 | if (!state) |
| 253 | return NULL; |
| 254 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 255 | SValBuilder &svalBuilder = C.getSValBuilder(); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 256 | ASTContext &Ctx = C.getASTContext(); |
| 257 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 258 | QualType sizeTy = Size->getType(); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 259 | QualType PtrTy = Ctx.getPointerType(Ctx.CharTy); |
| 260 | |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 261 | // Check that the first buffer is non-null. |
| 262 | SVal BufVal = state->getSVal(FirstBuf); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 263 | state = checkNonNull(C, state, FirstBuf, BufVal); |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 264 | if (!state) |
| 265 | return NULL; |
| 266 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 267 | // Get the access length and make sure it is known. |
| 268 | SVal LengthVal = state->getSVal(Size); |
| 269 | NonLoc *Length = dyn_cast<NonLoc>(&LengthVal); |
| 270 | if (!Length) |
| 271 | return state; |
| 272 | |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 273 | // Compute the offset of the last element to be accessed: size-1. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 274 | NonLoc One = cast<NonLoc>(svalBuilder.makeIntVal(1, sizeTy)); |
| 275 | NonLoc LastOffset = cast<NonLoc>(svalBuilder.evalBinOpNN(state, BO_Sub, |
| 276 | *Length, One, sizeTy)); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 277 | |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 278 | // Check that the first buffer is sufficently long. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 279 | SVal BufStart = svalBuilder.evalCast(BufVal, PtrTy, FirstBuf->getType()); |
Jordy Rose | b6a4026 | 2010-08-05 23:11:30 +0000 | [diff] [blame] | 280 | if (Loc *BufLoc = dyn_cast<Loc>(&BufStart)) { |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 281 | SVal BufEnd = svalBuilder.evalBinOpLN(state, BO_Add, *BufLoc, |
| 282 | LastOffset, PtrTy); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 283 | state = CheckLocation(C, state, FirstBuf, BufEnd, FirstIsDestination); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 284 | |
Jordy Rose | b6a4026 | 2010-08-05 23:11:30 +0000 | [diff] [blame] | 285 | // If the buffer isn't large enough, abort. |
| 286 | if (!state) |
| 287 | return NULL; |
| 288 | } |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 289 | |
| 290 | // If there's a second buffer, check it as well. |
| 291 | if (SecondBuf) { |
| 292 | BufVal = state->getSVal(SecondBuf); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 293 | state = checkNonNull(C, state, SecondBuf, BufVal); |
Jordy Rose | a6b808c | 2010-07-07 07:48:06 +0000 | [diff] [blame] | 294 | if (!state) |
| 295 | return NULL; |
| 296 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 297 | BufStart = svalBuilder.evalCast(BufVal, PtrTy, SecondBuf->getType()); |
Jordy Rose | b6a4026 | 2010-08-05 23:11:30 +0000 | [diff] [blame] | 298 | if (Loc *BufLoc = dyn_cast<Loc>(&BufStart)) { |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 299 | SVal BufEnd = svalBuilder.evalBinOpLN(state, BO_Add, *BufLoc, |
| 300 | LastOffset, PtrTy); |
Jordy Rose | b6a4026 | 2010-08-05 23:11:30 +0000 | [diff] [blame] | 301 | state = CheckLocation(C, state, SecondBuf, BufEnd); |
| 302 | } |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // Large enough or not, return this state! |
| 306 | return state; |
| 307 | } |
| 308 | |
| 309 | const GRState *CStringChecker::CheckOverlap(CheckerContext &C, |
| 310 | const GRState *state, |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 311 | const Expr *Size, |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 312 | const Expr *First, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 313 | const Expr *Second) const { |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 314 | // Do a simple check for overlap: if the two arguments are from the same |
| 315 | // buffer, see if the end of the first is greater than the start of the second |
| 316 | // or vice versa. |
| 317 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 318 | // If a previous check has failed, propagate the failure. |
| 319 | if (!state) |
| 320 | return NULL; |
| 321 | |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 322 | const GRState *stateTrue, *stateFalse; |
| 323 | |
| 324 | // Get the buffer values and make sure they're known locations. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 325 | SVal firstVal = state->getSVal(First); |
| 326 | SVal secondVal = state->getSVal(Second); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 327 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 328 | Loc *firstLoc = dyn_cast<Loc>(&firstVal); |
| 329 | if (!firstLoc) |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 330 | return state; |
| 331 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 332 | Loc *secondLoc = dyn_cast<Loc>(&secondVal); |
| 333 | if (!secondLoc) |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 334 | return state; |
| 335 | |
| 336 | // Are the two values the same? |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 337 | SValBuilder &svalBuilder = C.getSValBuilder(); |
| 338 | llvm::tie(stateTrue, stateFalse) = |
| 339 | state->assume(svalBuilder.evalEQ(state, *firstLoc, *secondLoc)); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 340 | |
| 341 | if (stateTrue && !stateFalse) { |
| 342 | // If the values are known to be equal, that's automatically an overlap. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 343 | emitOverlapBug(C, stateTrue, First, Second); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 344 | return NULL; |
| 345 | } |
| 346 | |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 347 | // assume the two expressions are not equal. |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 348 | assert(stateFalse); |
| 349 | state = stateFalse; |
| 350 | |
| 351 | // Which value comes first? |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 352 | ASTContext &Ctx = svalBuilder.getContext(); |
| 353 | QualType cmpTy = Ctx.IntTy; |
| 354 | SVal reverse = svalBuilder.evalBinOpLL(state, BO_GT, |
| 355 | *firstLoc, *secondLoc, cmpTy); |
| 356 | DefinedOrUnknownSVal *reverseTest = dyn_cast<DefinedOrUnknownSVal>(&reverse); |
| 357 | if (!reverseTest) |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 358 | return state; |
| 359 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 360 | llvm::tie(stateTrue, stateFalse) = state->assume(*reverseTest); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 361 | if (stateTrue) { |
| 362 | if (stateFalse) { |
| 363 | // If we don't know which one comes first, we can't perform this test. |
| 364 | return state; |
| 365 | } else { |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 366 | // Switch the values so that firstVal is before secondVal. |
| 367 | Loc *tmpLoc = firstLoc; |
| 368 | firstLoc = secondLoc; |
| 369 | secondLoc = tmpLoc; |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 370 | |
| 371 | // Switch the Exprs as well, so that they still correspond. |
| 372 | const Expr *tmpExpr = First; |
| 373 | First = Second; |
| 374 | Second = tmpExpr; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // Get the length, and make sure it too is known. |
| 379 | SVal LengthVal = state->getSVal(Size); |
| 380 | NonLoc *Length = dyn_cast<NonLoc>(&LengthVal); |
| 381 | if (!Length) |
| 382 | return state; |
| 383 | |
| 384 | // Convert the first buffer's start address to char*. |
| 385 | // Bail out if the cast fails. |
| 386 | QualType CharPtrTy = Ctx.getPointerType(Ctx.CharTy); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 387 | SVal FirstStart = svalBuilder.evalCast(*firstLoc, CharPtrTy, First->getType()); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 388 | Loc *FirstStartLoc = dyn_cast<Loc>(&FirstStart); |
| 389 | if (!FirstStartLoc) |
| 390 | return state; |
| 391 | |
| 392 | // Compute the end of the first buffer. Bail out if THAT fails. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 393 | SVal FirstEnd = svalBuilder.evalBinOpLN(state, BO_Add, |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 394 | *FirstStartLoc, *Length, CharPtrTy); |
| 395 | Loc *FirstEndLoc = dyn_cast<Loc>(&FirstEnd); |
| 396 | if (!FirstEndLoc) |
| 397 | return state; |
| 398 | |
| 399 | // Is the end of the first buffer past the start of the second buffer? |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 400 | SVal Overlap = svalBuilder.evalBinOpLL(state, BO_GT, |
| 401 | *FirstEndLoc, *secondLoc, cmpTy); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 402 | DefinedOrUnknownSVal *OverlapTest = dyn_cast<DefinedOrUnknownSVal>(&Overlap); |
| 403 | if (!OverlapTest) |
| 404 | return state; |
| 405 | |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 406 | llvm::tie(stateTrue, stateFalse) = state->assume(*OverlapTest); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 407 | |
| 408 | if (stateTrue && !stateFalse) { |
| 409 | // Overlap! |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 410 | emitOverlapBug(C, stateTrue, First, Second); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 411 | return NULL; |
| 412 | } |
| 413 | |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 414 | // assume the two expressions don't overlap. |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 415 | assert(stateFalse); |
| 416 | return stateFalse; |
| 417 | } |
| 418 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 419 | void CStringChecker::emitOverlapBug(CheckerContext &C, const GRState *state, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 420 | const Stmt *First, const Stmt *Second) const { |
Ted Kremenek | d048c6e | 2010-12-20 21:19:09 +0000 | [diff] [blame] | 421 | ExplodedNode *N = C.generateSink(state); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 422 | if (!N) |
| 423 | return; |
| 424 | |
| 425 | if (!BT_Overlap) |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 426 | BT_Overlap.reset(new BugType("Unix API", "Improper arguments")); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 427 | |
| 428 | // Generate a report for this bug. |
| 429 | RangedBugReport *report = |
| 430 | new RangedBugReport(*BT_Overlap, |
| 431 | "Arguments must not be overlapping buffers", N); |
| 432 | report->addRange(First->getSourceRange()); |
| 433 | report->addRange(Second->getSourceRange()); |
| 434 | |
| 435 | C.EmitReport(report); |
| 436 | } |
| 437 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 438 | const GRState *CStringChecker::setCStringLength(const GRState *state, |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 439 | const MemRegion *MR, |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 440 | SVal strLength) { |
| 441 | assert(!strLength.isUndef() && "Attempt to set an undefined string length"); |
| 442 | if (strLength.isUnknown()) |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 443 | return state; |
| 444 | |
| 445 | MR = MR->StripCasts(); |
| 446 | |
| 447 | switch (MR->getKind()) { |
| 448 | case MemRegion::StringRegionKind: |
| 449 | // FIXME: This can happen if we strcpy() into a string region. This is |
| 450 | // undefined [C99 6.4.5p6], but we should still warn about it. |
| 451 | return state; |
| 452 | |
| 453 | case MemRegion::SymbolicRegionKind: |
| 454 | case MemRegion::AllocaRegionKind: |
| 455 | case MemRegion::VarRegionKind: |
| 456 | case MemRegion::FieldRegionKind: |
| 457 | case MemRegion::ObjCIvarRegionKind: |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 458 | return state->set<CStringLength>(MR, strLength); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 459 | |
| 460 | case MemRegion::ElementRegionKind: |
| 461 | // FIXME: Handle element regions by upper-bounding the parent region's |
| 462 | // string length. |
| 463 | return state; |
| 464 | |
| 465 | default: |
| 466 | // Other regions (mostly non-data) can't have a reliable C string length. |
| 467 | // For now, just ignore the change. |
| 468 | // FIXME: These are rare but not impossible. We should output some kind of |
| 469 | // warning for things like strcpy((char[]){'a', 0}, "b"); |
| 470 | return state; |
| 471 | } |
| 472 | } |
| 473 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 474 | SVal CStringChecker::getCStringLengthForRegion(CheckerContext &C, |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 475 | const GRState *&state, |
| 476 | const Expr *Ex, |
| 477 | const MemRegion *MR) { |
| 478 | // If there's a recorded length, go ahead and return it. |
| 479 | const SVal *Recorded = state->get<CStringLength>(MR); |
| 480 | if (Recorded) |
| 481 | return *Recorded; |
| 482 | |
| 483 | // Otherwise, get a new symbol and update the state. |
| 484 | unsigned Count = C.getNodeBuilder().getCurrentBlockCount(); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 485 | SValBuilder &svalBuilder = C.getSValBuilder(); |
| 486 | QualType sizeTy = svalBuilder.getContext().getSizeType(); |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 487 | SVal strLength = svalBuilder.getMetadataSymbolVal(CStringChecker::getTag(), |
| 488 | MR, Ex, sizeTy, Count); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 489 | state = state->set<CStringLength>(MR, strLength); |
| 490 | return strLength; |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 493 | SVal CStringChecker::getCStringLength(CheckerContext &C, const GRState *&state, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 494 | const Expr *Ex, SVal Buf) const { |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 495 | const MemRegion *MR = Buf.getAsRegion(); |
| 496 | if (!MR) { |
| 497 | // If we can't get a region, see if it's something we /know/ isn't a |
| 498 | // C string. In the context of locations, the only time we can issue such |
| 499 | // a warning is for labels. |
| 500 | if (loc::GotoLabel *Label = dyn_cast<loc::GotoLabel>(&Buf)) { |
Ted Kremenek | d048c6e | 2010-12-20 21:19:09 +0000 | [diff] [blame] | 501 | if (ExplodedNode *N = C.generateNode(state)) { |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 502 | if (!BT_NotCString) |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 503 | BT_NotCString.reset(new BuiltinBug("API", |
| 504 | "Argument is not a null-terminated string.")); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 505 | |
| 506 | llvm::SmallString<120> buf; |
| 507 | llvm::raw_svector_ostream os(buf); |
| 508 | os << "Argument to byte string function is the address of the label '" |
Chris Lattner | 6810630 | 2011-02-17 05:38:27 +0000 | [diff] [blame] | 509 | << Label->getLabel()->getName() |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 510 | << "', which is not a null-terminated string"; |
| 511 | |
| 512 | // Generate a report for this bug. |
| 513 | EnhancedBugReport *report = new EnhancedBugReport(*BT_NotCString, |
| 514 | os.str(), N); |
| 515 | |
| 516 | report->addRange(Ex->getSourceRange()); |
| 517 | C.EmitReport(report); |
| 518 | } |
| 519 | |
| 520 | return UndefinedVal(); |
| 521 | } |
| 522 | |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 523 | // If it's not a region and not a label, give up. |
| 524 | return UnknownVal(); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 527 | // If we have a region, strip casts from it and see if we can figure out |
| 528 | // its length. For anything we can't figure out, just return UnknownVal. |
| 529 | MR = MR->StripCasts(); |
| 530 | |
| 531 | switch (MR->getKind()) { |
| 532 | case MemRegion::StringRegionKind: { |
| 533 | // Modifying the contents of string regions is undefined [C99 6.4.5p6], |
| 534 | // so we can assume that the byte length is the correct C string length. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 535 | SValBuilder &svalBuilder = C.getSValBuilder(); |
| 536 | QualType sizeTy = svalBuilder.getContext().getSizeType(); |
| 537 | const StringLiteral *strLit = cast<StringRegion>(MR)->getStringLiteral(); |
| 538 | return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 539 | } |
| 540 | case MemRegion::SymbolicRegionKind: |
| 541 | case MemRegion::AllocaRegionKind: |
| 542 | case MemRegion::VarRegionKind: |
| 543 | case MemRegion::FieldRegionKind: |
| 544 | case MemRegion::ObjCIvarRegionKind: |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 545 | return getCStringLengthForRegion(C, state, Ex, MR); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 546 | case MemRegion::CompoundLiteralRegionKind: |
| 547 | // FIXME: Can we track this? Is it necessary? |
| 548 | return UnknownVal(); |
| 549 | case MemRegion::ElementRegionKind: |
| 550 | // FIXME: How can we handle this? It's not good enough to subtract the |
| 551 | // offset from the base string length; consider "123\x00567" and &a[5]. |
| 552 | return UnknownVal(); |
| 553 | default: |
| 554 | // Other regions (mostly non-data) can't have a reliable C string length. |
| 555 | // In this case, an error is emitted and UndefinedVal is returned. |
| 556 | // The caller should always be prepared to handle this case. |
Ted Kremenek | d048c6e | 2010-12-20 21:19:09 +0000 | [diff] [blame] | 557 | if (ExplodedNode *N = C.generateNode(state)) { |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 558 | if (!BT_NotCString) |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 559 | BT_NotCString.reset(new BuiltinBug("API", |
| 560 | "Argument is not a null-terminated string.")); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 561 | |
| 562 | llvm::SmallString<120> buf; |
| 563 | llvm::raw_svector_ostream os(buf); |
| 564 | |
| 565 | os << "Argument to byte string function is "; |
| 566 | |
| 567 | if (SummarizeRegion(os, C.getASTContext(), MR)) |
| 568 | os << ", which is not a null-terminated string"; |
| 569 | else |
| 570 | os << "not a null-terminated string"; |
| 571 | |
| 572 | // Generate a report for this bug. |
| 573 | EnhancedBugReport *report = new EnhancedBugReport(*BT_NotCString, |
| 574 | os.str(), N); |
| 575 | |
| 576 | report->addRange(Ex->getSourceRange()); |
| 577 | C.EmitReport(report); |
| 578 | } |
| 579 | |
| 580 | return UndefinedVal(); |
| 581 | } |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 584 | const GRState *CStringChecker::InvalidateBuffer(CheckerContext &C, |
| 585 | const GRState *state, |
| 586 | const Expr *E, SVal V) { |
| 587 | Loc *L = dyn_cast<Loc>(&V); |
| 588 | if (!L) |
| 589 | return state; |
| 590 | |
| 591 | // FIXME: This is a simplified version of what's in CFRefCount.cpp -- it makes |
| 592 | // some assumptions about the value that CFRefCount can't. Even so, it should |
| 593 | // probably be refactored. |
| 594 | if (loc::MemRegionVal* MR = dyn_cast<loc::MemRegionVal>(L)) { |
| 595 | const MemRegion *R = MR->getRegion()->StripCasts(); |
| 596 | |
| 597 | // Are we dealing with an ElementRegion? If so, we should be invalidating |
| 598 | // the super-region. |
| 599 | if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) { |
| 600 | R = ER->getSuperRegion(); |
| 601 | // FIXME: What about layers of ElementRegions? |
| 602 | } |
| 603 | |
| 604 | // Invalidate this region. |
| 605 | unsigned Count = C.getNodeBuilder().getCurrentBlockCount(); |
Ted Kremenek | 2534528 | 2011-02-11 19:48:15 +0000 | [diff] [blame] | 606 | return state->invalidateRegion(R, E, Count, NULL); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | // If we have a non-region value by chance, just remove the binding. |
| 610 | // FIXME: is this necessary or correct? This handles the non-Region |
| 611 | // cases. Is it ever valid to store to these? |
| 612 | return state->unbindLoc(*L); |
| 613 | } |
| 614 | |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 615 | bool CStringChecker::SummarizeRegion(llvm::raw_ostream& os, ASTContext& Ctx, |
| 616 | const MemRegion *MR) { |
| 617 | const TypedRegion *TR = dyn_cast<TypedRegion>(MR); |
| 618 | if (!TR) |
| 619 | return false; |
| 620 | |
| 621 | switch (TR->getKind()) { |
| 622 | case MemRegion::FunctionTextRegionKind: { |
| 623 | const FunctionDecl *FD = cast<FunctionTextRegion>(TR)->getDecl(); |
| 624 | if (FD) |
| 625 | os << "the address of the function '" << FD << "'"; |
| 626 | else |
| 627 | os << "the address of a function"; |
| 628 | return true; |
| 629 | } |
| 630 | case MemRegion::BlockTextRegionKind: |
| 631 | os << "block text"; |
| 632 | return true; |
| 633 | case MemRegion::BlockDataRegionKind: |
| 634 | os << "a block"; |
| 635 | return true; |
| 636 | case MemRegion::CXXThisRegionKind: |
Zhongxing Xu | 02fe28c | 2010-11-26 08:52:48 +0000 | [diff] [blame] | 637 | case MemRegion::CXXTempObjectRegionKind: |
| 638 | os << "a C++ temp object of type " << TR->getValueType().getAsString(); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 639 | return true; |
| 640 | case MemRegion::VarRegionKind: |
Zhongxing Xu | 018220c | 2010-08-11 06:10:55 +0000 | [diff] [blame] | 641 | os << "a variable of type" << TR->getValueType().getAsString(); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 642 | return true; |
| 643 | case MemRegion::FieldRegionKind: |
Zhongxing Xu | 018220c | 2010-08-11 06:10:55 +0000 | [diff] [blame] | 644 | os << "a field of type " << TR->getValueType().getAsString(); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 645 | return true; |
| 646 | case MemRegion::ObjCIvarRegionKind: |
Zhongxing Xu | 018220c | 2010-08-11 06:10:55 +0000 | [diff] [blame] | 647 | os << "an instance variable of type " << TR->getValueType().getAsString(); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 648 | return true; |
| 649 | default: |
| 650 | return false; |
| 651 | } |
| 652 | } |
| 653 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 654 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 655 | // evaluation of individual function calls. |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 656 | //===----------------------------------------------------------------------===// |
| 657 | |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 658 | void CStringChecker::evalCopyCommon(CheckerContext &C, const GRState *state, |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 659 | const Expr *Size, const Expr *Dest, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 660 | const Expr *Source, bool Restricted) const { |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 661 | // See if the size argument is zero. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 662 | SVal sizeVal = state->getSVal(Size); |
| 663 | QualType sizeTy = Size->getType(); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 664 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 665 | const GRState *stateZeroSize, *stateNonZeroSize; |
| 666 | llvm::tie(stateZeroSize, stateNonZeroSize) = assumeZero(C, state, sizeVal, sizeTy); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 667 | |
| 668 | // If the size is zero, there won't be any actual memory access. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 669 | if (stateZeroSize) |
| 670 | C.addTransition(stateZeroSize); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 671 | |
| 672 | // If the size can be nonzero, we have to check the other arguments. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 673 | if (stateNonZeroSize) { |
| 674 | state = stateNonZeroSize; |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 675 | state = CheckBufferAccess(C, state, Size, Dest, Source, |
| 676 | /* FirstIsDst = */ true); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 677 | if (Restricted) |
| 678 | state = CheckOverlap(C, state, Size, Dest, Source); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 679 | |
| 680 | if (state) { |
| 681 | // Invalidate the destination. |
| 682 | // FIXME: Even if we can't perfectly model the copy, we should see if we |
| 683 | // can use LazyCompoundVals to copy the source values into the destination. |
| 684 | // This would probably remove any existing bindings past the end of the |
| 685 | // copied region, but that's still an improvement over blank invalidation. |
| 686 | state = InvalidateBuffer(C, state, Dest, state->getSVal(Dest)); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 687 | C.addTransition(state); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 688 | } |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
| 692 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 693 | void CStringChecker::evalMemcpy(CheckerContext &C, const CallExpr *CE) const { |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 694 | // void *memcpy(void *restrict dst, const void *restrict src, size_t n); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 695 | // The return value is the address of the destination buffer. |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 696 | const Expr *Dest = CE->getArg(0); |
| 697 | const GRState *state = C.getState(); |
| 698 | state = state->BindExpr(CE, state->getSVal(Dest)); |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 699 | evalCopyCommon(C, state, CE->getArg(2), Dest, CE->getArg(1), true); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 702 | void CStringChecker::evalMemmove(CheckerContext &C, const CallExpr *CE) const { |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 703 | // void *memmove(void *dst, const void *src, size_t n); |
| 704 | // The return value is the address of the destination buffer. |
| 705 | const Expr *Dest = CE->getArg(0); |
| 706 | const GRState *state = C.getState(); |
| 707 | state = state->BindExpr(CE, state->getSVal(Dest)); |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 708 | evalCopyCommon(C, state, CE->getArg(2), Dest, CE->getArg(1)); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 711 | void CStringChecker::evalBcopy(CheckerContext &C, const CallExpr *CE) const { |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 712 | // void bcopy(const void *src, void *dst, size_t n); |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 713 | evalCopyCommon(C, C.getState(), CE->getArg(2), CE->getArg(1), CE->getArg(0)); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 716 | void CStringChecker::evalMemcmp(CheckerContext &C, const CallExpr *CE) const { |
Jordy Rose | bc56d1f | 2010-07-07 08:15:01 +0000 | [diff] [blame] | 717 | // int memcmp(const void *s1, const void *s2, size_t n); |
| 718 | const Expr *Left = CE->getArg(0); |
| 719 | const Expr *Right = CE->getArg(1); |
| 720 | const Expr *Size = CE->getArg(2); |
| 721 | |
| 722 | const GRState *state = C.getState(); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 723 | SValBuilder &svalBuilder = C.getSValBuilder(); |
Jordy Rose | bc56d1f | 2010-07-07 08:15:01 +0000 | [diff] [blame] | 724 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 725 | // See if the size argument is zero. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 726 | SVal sizeVal = state->getSVal(Size); |
| 727 | QualType sizeTy = Size->getType(); |
Jordy Rose | bc56d1f | 2010-07-07 08:15:01 +0000 | [diff] [blame] | 728 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 729 | const GRState *stateZeroSize, *stateNonZeroSize; |
| 730 | llvm::tie(stateZeroSize, stateNonZeroSize) = |
| 731 | assumeZero(C, state, sizeVal, sizeTy); |
Jordy Rose | bc56d1f | 2010-07-07 08:15:01 +0000 | [diff] [blame] | 732 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 733 | // If the size can be zero, the result will be 0 in that case, and we don't |
| 734 | // have to check either of the buffers. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 735 | if (stateZeroSize) { |
| 736 | state = stateZeroSize; |
| 737 | state = state->BindExpr(CE, svalBuilder.makeZeroVal(CE->getType())); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 738 | C.addTransition(state); |
Jordy Rose | bc56d1f | 2010-07-07 08:15:01 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 741 | // If the size can be nonzero, we have to check the other arguments. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 742 | if (stateNonZeroSize) { |
| 743 | state = stateNonZeroSize; |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 744 | // If we know the two buffers are the same, we know the result is 0. |
| 745 | // First, get the two buffers' addresses. Another checker will have already |
| 746 | // made sure they're not undefined. |
| 747 | DefinedOrUnknownSVal LV = cast<DefinedOrUnknownSVal>(state->getSVal(Left)); |
| 748 | DefinedOrUnknownSVal RV = cast<DefinedOrUnknownSVal>(state->getSVal(Right)); |
Jordy Rose | bc56d1f | 2010-07-07 08:15:01 +0000 | [diff] [blame] | 749 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 750 | // See if they are the same. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 751 | DefinedOrUnknownSVal SameBuf = svalBuilder.evalEQ(state, LV, RV); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 752 | const GRState *StSameBuf, *StNotSameBuf; |
Ted Kremenek | 28f47b9 | 2010-12-01 22:16:56 +0000 | [diff] [blame] | 753 | llvm::tie(StSameBuf, StNotSameBuf) = state->assume(SameBuf); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 754 | |
| 755 | // If the two arguments might be the same buffer, we know the result is zero, |
| 756 | // and we only need to check one size. |
| 757 | if (StSameBuf) { |
| 758 | state = StSameBuf; |
| 759 | state = CheckBufferAccess(C, state, Size, Left); |
| 760 | if (state) { |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 761 | state = StSameBuf->BindExpr(CE, svalBuilder.makeZeroVal(CE->getType())); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 762 | C.addTransition(state); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | // If the two arguments might be different buffers, we have to check the |
| 767 | // size of both of them. |
| 768 | if (StNotSameBuf) { |
| 769 | state = StNotSameBuf; |
| 770 | state = CheckBufferAccess(C, state, Size, Left, Right); |
| 771 | if (state) { |
| 772 | // The return value is the comparison result, which we don't know. |
| 773 | unsigned Count = C.getNodeBuilder().getCurrentBlockCount(); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 774 | SVal CmpV = svalBuilder.getConjuredSymbolVal(NULL, CE, Count); |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 775 | state = state->BindExpr(CE, CmpV); |
| 776 | C.addTransition(state); |
| 777 | } |
| 778 | } |
| 779 | } |
Jordy Rose | bc56d1f | 2010-07-07 08:15:01 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 782 | void CStringChecker::evalstrLength(CheckerContext &C, |
| 783 | const CallExpr *CE) const { |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 784 | // size_t strlen(const char *s); |
Ted Kremenek | be4242c | 2011-02-22 04:55:05 +0000 | [diff] [blame] | 785 | evalstrLengthCommon(C, CE, /* IsStrnlen = */ false); |
| 786 | } |
| 787 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 788 | void CStringChecker::evalstrnLength(CheckerContext &C, |
| 789 | const CallExpr *CE) const { |
Ted Kremenek | be4242c | 2011-02-22 04:55:05 +0000 | [diff] [blame] | 790 | // size_t strnlen(const char *s, size_t maxlen); |
| 791 | evalstrLengthCommon(C, CE, /* IsStrnlen = */ true); |
| 792 | } |
| 793 | |
| 794 | void CStringChecker::evalstrLengthCommon(CheckerContext &C, const CallExpr *CE, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 795 | bool IsStrnlen) const { |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 796 | const GRState *state = C.getState(); |
| 797 | const Expr *Arg = CE->getArg(0); |
| 798 | SVal ArgVal = state->getSVal(Arg); |
| 799 | |
| 800 | // Check that the argument is non-null. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 801 | state = checkNonNull(C, state, Arg, ArgVal); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 802 | |
| 803 | if (state) { |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 804 | SVal strLength = getCStringLength(C, state, Arg, ArgVal); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 805 | |
| 806 | // If the argument isn't a valid C string, there's no valid state to |
| 807 | // transition to. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 808 | if (strLength.isUndef()) |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 809 | return; |
| 810 | |
Ted Kremenek | be4242c | 2011-02-22 04:55:05 +0000 | [diff] [blame] | 811 | // If the check is for strnlen() then bind the return value to no more than |
| 812 | // the maxlen value. |
| 813 | if (IsStrnlen) { |
| 814 | const Expr *maxlenExpr = CE->getArg(1); |
| 815 | SVal maxlenVal = state->getSVal(maxlenExpr); |
| 816 | |
| 817 | NonLoc *strLengthNL = dyn_cast<NonLoc>(&strLength); |
| 818 | NonLoc *maxlenValNL = dyn_cast<NonLoc>(&maxlenVal); |
| 819 | |
| 820 | QualType cmpTy = C.getSValBuilder().getContext().IntTy; |
| 821 | const GRState *stateTrue, *stateFalse; |
| 822 | |
| 823 | // Check if the strLength is greater than or equal to the maxlen |
| 824 | llvm::tie(stateTrue, stateFalse) = |
| 825 | state->assume(cast<DefinedOrUnknownSVal> |
| 826 | (C.getSValBuilder().evalBinOpNN(state, BO_GE, |
| 827 | *strLengthNL, *maxlenValNL, |
| 828 | cmpTy))); |
| 829 | |
| 830 | // If the strLength is greater than or equal to the maxlen, set strLength |
| 831 | // to maxlen |
| 832 | if (stateTrue && !stateFalse) { |
| 833 | strLength = maxlenVal; |
| 834 | } |
| 835 | } |
| 836 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 837 | // If getCStringLength couldn't figure out the length, conjure a return |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 838 | // value, so it can be used in constraints, at least. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 839 | if (strLength.isUnknown()) { |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 840 | unsigned Count = C.getNodeBuilder().getCurrentBlockCount(); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 841 | strLength = C.getSValBuilder().getConjuredSymbolVal(NULL, CE, Count); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 842 | } |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 843 | |
| 844 | // Bind the return value. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 845 | state = state->BindExpr(CE, strLength); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 846 | C.addTransition(state); |
Jordy Rose | 19c5dd1 | 2010-07-27 01:37:31 +0000 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 850 | void CStringChecker::evalStrcpy(CheckerContext &C, const CallExpr *CE) const { |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 851 | // char *strcpy(char *restrict dst, const char *restrict src); |
Ted Kremenek | 0ef473f | 2011-02-22 04:58:34 +0000 | [diff] [blame] | 852 | evalStrcpyCommon(C, CE, /* returnEnd = */ false, /* isStrncpy = */ false); |
| 853 | } |
| 854 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 855 | void CStringChecker::evalStrncpy(CheckerContext &C, const CallExpr *CE) const { |
Ted Kremenek | 0ef473f | 2011-02-22 04:58:34 +0000 | [diff] [blame] | 856 | // char *strcpy(char *restrict dst, const char *restrict src); |
| 857 | evalStrcpyCommon(C, CE, /* returnEnd = */ false, /* isStrncpy = */ true); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 860 | void CStringChecker::evalStpcpy(CheckerContext &C, const CallExpr *CE) const { |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 861 | // char *stpcpy(char *restrict dst, const char *restrict src); |
Ted Kremenek | 0ef473f | 2011-02-22 04:58:34 +0000 | [diff] [blame] | 862 | evalStrcpyCommon(C, CE, /* returnEnd = */ true, /* isStrncpy = */ false); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 865 | void CStringChecker::evalStrcpyCommon(CheckerContext &C, const CallExpr *CE, |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 866 | bool returnEnd, bool isStrncpy) const { |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 867 | const GRState *state = C.getState(); |
| 868 | |
| 869 | // Check that the destination is non-null |
| 870 | const Expr *Dst = CE->getArg(0); |
| 871 | SVal DstVal = state->getSVal(Dst); |
| 872 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 873 | state = checkNonNull(C, state, Dst, DstVal); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 874 | if (!state) |
| 875 | return; |
| 876 | |
| 877 | // Check that the source is non-null. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 878 | const Expr *srcExpr = CE->getArg(1); |
| 879 | SVal srcVal = state->getSVal(srcExpr); |
| 880 | state = checkNonNull(C, state, srcExpr, srcVal); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 881 | if (!state) |
| 882 | return; |
| 883 | |
| 884 | // Get the string length of the source. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 885 | SVal strLength = getCStringLength(C, state, srcExpr, srcVal); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 886 | |
| 887 | // If the source isn't a valid C string, give up. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 888 | if (strLength.isUndef()) |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 889 | return; |
| 890 | |
Ted Kremenek | 0ef473f | 2011-02-22 04:58:34 +0000 | [diff] [blame] | 891 | if (isStrncpy) { |
| 892 | // Get the max number of characters to copy |
| 893 | const Expr *lenExpr = CE->getArg(2); |
| 894 | SVal lenVal = state->getSVal(lenExpr); |
| 895 | |
| 896 | NonLoc *strLengthNL = dyn_cast<NonLoc>(&strLength); |
| 897 | NonLoc *lenValNL = dyn_cast<NonLoc>(&lenVal); |
| 898 | |
| 899 | QualType cmpTy = C.getSValBuilder().getContext().IntTy; |
| 900 | const GRState *stateTrue, *stateFalse; |
| 901 | |
| 902 | // Check if the max number to copy is less than the length of the src |
| 903 | llvm::tie(stateTrue, stateFalse) = |
| 904 | state->assume(cast<DefinedOrUnknownSVal> |
| 905 | (C.getSValBuilder().evalBinOpNN(state, BO_GT, |
| 906 | *strLengthNL, *lenValNL, |
| 907 | cmpTy))); |
| 908 | |
| 909 | if (stateTrue) { |
| 910 | // Max number to copy is less than the length of the src, so the actual |
| 911 | // strLength copied is the max number arg. |
| 912 | strLength = lenVal; |
| 913 | } |
| 914 | } |
| 915 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 916 | SVal Result = (returnEnd ? UnknownVal() : DstVal); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 917 | |
| 918 | // If the destination is a MemRegion, try to check for a buffer overflow and |
| 919 | // record the new string length. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 920 | if (loc::MemRegionVal *dstRegVal = dyn_cast<loc::MemRegionVal>(&DstVal)) { |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 921 | // If the length is known, we can check for an overflow. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 922 | if (NonLoc *knownStrLength = dyn_cast<NonLoc>(&strLength)) { |
| 923 | SVal lastElement = |
| 924 | C.getSValBuilder().evalBinOpLN(state, BO_Add, *dstRegVal, |
| 925 | *knownStrLength, Dst->getType()); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 926 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 927 | state = CheckLocation(C, state, Dst, lastElement, /* IsDst = */ true); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 928 | if (!state) |
| 929 | return; |
| 930 | |
| 931 | // If this is a stpcpy-style copy, the last element is the return value. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 932 | if (returnEnd) |
| 933 | Result = lastElement; |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | // Invalidate the destination. This must happen before we set the C string |
| 937 | // length because invalidation will clear the length. |
| 938 | // FIXME: Even if we can't perfectly model the copy, we should see if we |
| 939 | // can use LazyCompoundVals to copy the source values into the destination. |
| 940 | // This would probably remove any existing bindings past the end of the |
| 941 | // string, but that's still an improvement over blank invalidation. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 942 | state = InvalidateBuffer(C, state, Dst, *dstRegVal); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 943 | |
| 944 | // Set the C string length of the destination. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 945 | state = setCStringLength(state, dstRegVal->getRegion(), strLength); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | // If this is a stpcpy-style copy, but we were unable to check for a buffer |
| 949 | // overflow, we still need a result. Conjure a return value. |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 950 | if (returnEnd && Result.isUnknown()) { |
| 951 | SValBuilder &svalBuilder = C.getSValBuilder(); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 952 | unsigned Count = C.getNodeBuilder().getCurrentBlockCount(); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 953 | strLength = svalBuilder.getConjuredSymbolVal(NULL, CE, Count); |
Jordy Rose | e64f311 | 2010-08-16 07:51:42 +0000 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | // Set the return value. |
| 957 | state = state->BindExpr(CE, Result); |
| 958 | C.addTransition(state); |
| 959 | } |
| 960 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 961 | //===----------------------------------------------------------------------===// |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 962 | // The driver method, and other Checker callbacks. |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 963 | //===----------------------------------------------------------------------===// |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 964 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 965 | bool CStringChecker::evalCall(const CallExpr *CE, CheckerContext &C) const { |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 966 | // Get the callee. All the functions we care about are C functions |
| 967 | // with simple identifiers. |
| 968 | const GRState *state = C.getState(); |
| 969 | const Expr *Callee = CE->getCallee(); |
| 970 | const FunctionDecl *FD = state->getSVal(Callee).getAsFunctionDecl(); |
| 971 | |
| 972 | if (!FD) |
| 973 | return false; |
| 974 | |
| 975 | // Get the name of the callee. If it's a builtin, strip off the prefix. |
Douglas Gregor | 90d26a4 | 2010-11-01 23:16:05 +0000 | [diff] [blame] | 976 | IdentifierInfo *II = FD->getIdentifier(); |
| 977 | if (!II) // if no identifier, not a simple C function |
| 978 | return false; |
| 979 | llvm::StringRef Name = II->getName(); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 980 | if (Name.startswith("__builtin_")) |
| 981 | Name = Name.substr(10); |
| 982 | |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 983 | FnCheck evalFunction = llvm::StringSwitch<FnCheck>(Name) |
| 984 | .Cases("memcpy", "__memcpy_chk", &CStringChecker::evalMemcpy) |
| 985 | .Cases("memcmp", "bcmp", &CStringChecker::evalMemcmp) |
| 986 | .Cases("memmove", "__memmove_chk", &CStringChecker::evalMemmove) |
| 987 | .Cases("strcpy", "__strcpy_chk", &CStringChecker::evalStrcpy) |
Ted Kremenek | 0ef473f | 2011-02-22 04:58:34 +0000 | [diff] [blame] | 988 | .Cases("strncpy", "__strncpy_chk", &CStringChecker::evalStrncpy) |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 989 | .Cases("stpcpy", "__stpcpy_chk", &CStringChecker::evalStpcpy) |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 990 | .Case("strlen", &CStringChecker::evalstrLength) |
Ted Kremenek | be4242c | 2011-02-22 04:55:05 +0000 | [diff] [blame] | 991 | .Case("strnlen", &CStringChecker::evalstrnLength) |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 992 | .Case("bcopy", &CStringChecker::evalBcopy) |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 993 | .Default(NULL); |
| 994 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 995 | // If the callee isn't a string function, let another checker handle it. |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 996 | if (!evalFunction) |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 997 | return false; |
| 998 | |
Jordy Rose | d325ffb | 2010-07-08 23:57:29 +0000 | [diff] [blame] | 999 | // Check and evaluate the call. |
Ted Kremenek | 9c14953 | 2010-12-01 21:57:22 +0000 | [diff] [blame] | 1000 | (this->*evalFunction)(C, CE); |
Jordy Rose | ccbf7ee | 2010-07-06 23:11:01 +0000 | [diff] [blame] | 1001 | return true; |
| 1002 | } |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1003 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 1004 | void CStringChecker::checkPreStmt(const DeclStmt *DS, CheckerContext &C) const { |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1005 | // Record string length for char a[] = "abc"; |
| 1006 | const GRState *state = C.getState(); |
| 1007 | |
| 1008 | for (DeclStmt::const_decl_iterator I = DS->decl_begin(), E = DS->decl_end(); |
| 1009 | I != E; ++I) { |
| 1010 | const VarDecl *D = dyn_cast<VarDecl>(*I); |
| 1011 | if (!D) |
| 1012 | continue; |
| 1013 | |
| 1014 | // FIXME: Handle array fields of structs. |
| 1015 | if (!D->getType()->isArrayType()) |
| 1016 | continue; |
| 1017 | |
| 1018 | const Expr *Init = D->getInit(); |
| 1019 | if (!Init) |
| 1020 | continue; |
| 1021 | if (!isa<StringLiteral>(Init)) |
| 1022 | continue; |
| 1023 | |
| 1024 | Loc VarLoc = state->getLValue(D, C.getPredecessor()->getLocationContext()); |
| 1025 | const MemRegion *MR = VarLoc.getAsRegion(); |
| 1026 | if (!MR) |
| 1027 | continue; |
| 1028 | |
| 1029 | SVal StrVal = state->getSVal(Init); |
| 1030 | assert(StrVal.isValid() && "Initializer string is unknown or undefined"); |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 1031 | DefinedOrUnknownSVal strLength |
| 1032 | = cast<DefinedOrUnknownSVal>(getCStringLength(C, state, Init, StrVal)); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1033 | |
Ted Kremenek | c8413fd | 2010-12-02 07:49:45 +0000 | [diff] [blame] | 1034 | state = state->set<CStringLength>(MR, strLength); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | C.addTransition(state); |
| 1038 | } |
| 1039 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 1040 | bool CStringChecker::wantsRegionChangeUpdate(const GRState *state) const { |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1041 | CStringLength::EntryMap Entries = state->get<CStringLength>(); |
| 1042 | return !Entries.isEmpty(); |
| 1043 | } |
| 1044 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 1045 | const GRState * |
| 1046 | CStringChecker::checkRegionChanges(const GRState *state, |
| 1047 | const MemRegion * const *Begin, |
| 1048 | const MemRegion * const *End) const { |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1049 | CStringLength::EntryMap Entries = state->get<CStringLength>(); |
| 1050 | if (Entries.isEmpty()) |
| 1051 | return state; |
| 1052 | |
| 1053 | llvm::SmallPtrSet<const MemRegion *, 8> Invalidated; |
| 1054 | llvm::SmallPtrSet<const MemRegion *, 32> SuperRegions; |
| 1055 | |
| 1056 | // First build sets for the changed regions and their super-regions. |
| 1057 | for ( ; Begin != End; ++Begin) { |
| 1058 | const MemRegion *MR = *Begin; |
| 1059 | Invalidated.insert(MR); |
| 1060 | |
| 1061 | SuperRegions.insert(MR); |
| 1062 | while (const SubRegion *SR = dyn_cast<SubRegion>(MR)) { |
| 1063 | MR = SR->getSuperRegion(); |
| 1064 | SuperRegions.insert(MR); |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | CStringLength::EntryMap::Factory &F = state->get_context<CStringLength>(); |
| 1069 | |
| 1070 | // Then loop over the entries in the current state. |
| 1071 | for (CStringLength::EntryMap::iterator I = Entries.begin(), |
| 1072 | E = Entries.end(); I != E; ++I) { |
| 1073 | const MemRegion *MR = I.getKey(); |
| 1074 | |
| 1075 | // Is this entry for a super-region of a changed region? |
| 1076 | if (SuperRegions.count(MR)) { |
Ted Kremenek | 3baf672 | 2010-11-24 00:54:37 +0000 | [diff] [blame] | 1077 | Entries = F.remove(Entries, MR); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1078 | continue; |
| 1079 | } |
| 1080 | |
| 1081 | // Is this entry for a sub-region of a changed region? |
| 1082 | const MemRegion *Super = MR; |
| 1083 | while (const SubRegion *SR = dyn_cast<SubRegion>(Super)) { |
| 1084 | Super = SR->getSuperRegion(); |
| 1085 | if (Invalidated.count(Super)) { |
Ted Kremenek | 3baf672 | 2010-11-24 00:54:37 +0000 | [diff] [blame] | 1086 | Entries = F.remove(Entries, MR); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1087 | break; |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | return state->set<CStringLength>(Entries); |
| 1093 | } |
| 1094 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 1095 | void CStringChecker::checkLiveSymbols(const GRState *state, |
| 1096 | SymbolReaper &SR) const { |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1097 | // Mark all symbols in our string length map as valid. |
| 1098 | CStringLength::EntryMap Entries = state->get<CStringLength>(); |
| 1099 | |
| 1100 | for (CStringLength::EntryMap::iterator I = Entries.begin(), E = Entries.end(); |
| 1101 | I != E; ++I) { |
| 1102 | SVal Len = I.getData(); |
| 1103 | if (SymbolRef Sym = Len.getAsSymbol()) |
| 1104 | SR.markInUse(Sym); |
| 1105 | } |
| 1106 | } |
| 1107 | |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 1108 | void CStringChecker::checkDeadSymbols(SymbolReaper &SR, |
| 1109 | CheckerContext &C) const { |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1110 | if (!SR.hasDeadSymbols()) |
| 1111 | return; |
| 1112 | |
| 1113 | const GRState *state = C.getState(); |
| 1114 | CStringLength::EntryMap Entries = state->get<CStringLength>(); |
| 1115 | if (Entries.isEmpty()) |
| 1116 | return; |
| 1117 | |
| 1118 | CStringLength::EntryMap::Factory &F = state->get_context<CStringLength>(); |
| 1119 | for (CStringLength::EntryMap::iterator I = Entries.begin(), E = Entries.end(); |
| 1120 | I != E; ++I) { |
| 1121 | SVal Len = I.getData(); |
| 1122 | if (SymbolRef Sym = Len.getAsSymbol()) { |
| 1123 | if (SR.isDead(Sym)) |
Ted Kremenek | 3baf672 | 2010-11-24 00:54:37 +0000 | [diff] [blame] | 1124 | Entries = F.remove(Entries, I.getKey()); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | state = state->set<CStringLength>(Entries); |
Ted Kremenek | d048c6e | 2010-12-20 21:19:09 +0000 | [diff] [blame] | 1129 | C.generateNode(state); |
Jordy Rose | a526154 | 2010-08-14 21:02:52 +0000 | [diff] [blame] | 1130 | } |
Argyrios Kyrtzidis | 183ff98 | 2011-02-24 01:05:30 +0000 | [diff] [blame] | 1131 | |
| 1132 | void ento::registerCStringChecker(CheckerManager &mgr) { |
| 1133 | mgr.registerChecker<CStringChecker>(); |
| 1134 | } |