Ejemplo n.º 1
0
void ento::RegisterAppleChecks(ExprEngine& Eng, const Decl &D) {
  Eng.registerCheck(new NilArgChecker());
  Eng.registerCheck(new CFNumberCreateChecker());
  RegisterNSErrorChecks(Eng.getBugReporter(), Eng, D);
  RegisterNSAutoreleasePoolChecks(Eng);
  Eng.registerCheck(new CFRetainReleaseChecker());
  Eng.registerCheck(new ClassReleaseChecker());
}
Ejemplo n.º 2
0
void UndefBranchChecker::checkBranchCondition(const Stmt *Condition,
                                              BranchNodeBuilder &Builder,
                                              ExprEngine &Eng) const {
  const GRState *state = Builder.getState();
  SVal X = state->getSVal(Condition);
  if (X.isUndef()) {
    ExplodedNode *N = Builder.generateNode(state, true);
    if (N) {
      N->markAsSink();
      if (!BT)
        BT.reset(
               new BuiltinBug("Branch condition evaluates to a garbage value"));

      // What's going on here: we want to highlight the subexpression of the
      // condition that is the most likely source of the "uninitialized
      // branch condition."  We do a recursive walk of the condition's
      // subexpressions and roughly look for the most nested subexpression
      // that binds to Undefined.  We then highlight that expression's range.
      BlockEdge B = cast<BlockEdge>(N->getLocation());
      const Expr* Ex = cast<Expr>(B.getSrc()->getTerminatorCondition());
      assert (Ex && "Block must have a terminator.");

      // Get the predecessor node and check if is a PostStmt with the Stmt
      // being the terminator condition.  We want to inspect the state
      // of that node instead because it will contain main information about
      // the subexpressions.
      assert (!N->pred_empty());

      // Note: any predecessor will do.  They should have identical state,
      // since all the BlockEdge did was act as an error sink since the value
      // had to already be undefined.
      ExplodedNode *PrevN = *N->pred_begin();
      ProgramPoint P = PrevN->getLocation();
      const GRState* St = N->getState();

      if (PostStmt* PS = dyn_cast<PostStmt>(&P))
        if (PS->getStmt() == Ex)
          St = PrevN->getState();

      FindUndefExpr FindIt(Eng.getStateManager(), St);
      Ex = FindIt.FindExpr(Ex);

      // Emit the bug report.
      EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getDescription(),N);
      R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, Ex);
      R->addRange(Ex->getSourceRange());

      Eng.getBugReporter().EmitReport(R);
    }

    Builder.markInfeasible(true);
    Builder.markInfeasible(false);
  }
}
Ejemplo n.º 3
0
void MallocChecker::checkEndPath(EndOfFunctionNodeBuilder &B,
                                 ExprEngine &Eng) const {
  const GRState *state = B.getState();
  RegionStateTy M = state->get<RegionState>();

  for (RegionStateTy::iterator I = M.begin(), E = M.end(); I != E; ++I) {
    RefState RS = I->second;
    if (RS.isAllocated()) {
      ExplodedNode *N = B.generateNode(state);
      if (N) {
        if (!BT_Leak)
          BT_Leak.reset(new BuiltinBug("Memory leak",
                    "Allocated memory never released. Potential memory leak."));
        BugReport *R = new BugReport(*BT_Leak, BT_Leak->getDescription(), N);
        Eng.getBugReporter().EmitReport(R);
      }
    }
  }
}
Ejemplo n.º 4
0
void StreamChecker::checkEndPath(EndOfFunctionNodeBuilder &B,
                                 ExprEngine &Eng) const {
    const GRState *state = B.getState();
    typedef llvm::ImmutableMap<SymbolRef, StreamState> SymMap;
    SymMap M = state->get<StreamState>();

    for (SymMap::iterator I = M.begin(), E = M.end(); I != E; ++I) {
        StreamState SS = I->second;
        if (SS.isOpened()) {
            ExplodedNode *N = B.generateNode(state);
            if (N) {
                if (!BT_ResourceLeak)
                    BT_ResourceLeak.reset(new BuiltinBug("Resource Leak",
                                                         "Opened File never closed. Potential Resource leak."));
                BugReport *R = new BugReport(*BT_ResourceLeak,
                                             BT_ResourceLeak->getDescription(), N);
                Eng.getBugReporter().EmitReport(R);
            }
        }
    }
}