[cfe-commits] r137720 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp test/Analysis/keychainAPI.m

Anna Zaks ganna at apple.com
Tue Aug 16 09:30:24 PDT 2011


Author: zaks
Date: Tue Aug 16 11:30:24 2011
New Revision: 137720

URL: http://llvm.org/viewvc/llvm-project?rev=137720&view=rev
Log:
MacOSKeychainAPIChecker: Do not report double allocation if first allocation returned an error.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
    cfe/trunk/test/Analysis/keychainAPI.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp?rev=137720&r1=137719&r2=137720&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp Tue Aug 16 11:30:24 2011
@@ -230,23 +230,25 @@
     const Expr *ArgExpr = CE->getArg(FunctionsToTrack[idx].Param);
     if (SymbolRef V = getAsPointeeSymbol(ArgExpr, C))
       if (const AllocationState *AS = State->get<AllocatedData>(V)) {
-        // Remove the value from the state. The new symbol will be added for
-        // tracking when the second allocator is processed in checkPostStmt().
-        State = State->remove<AllocatedData>(V);
-        ExplodedNode *N = C.generateNode(State);
-        if (!N)
-          return;
-        initBugType();
-        llvm::SmallString<128> sbuf;
-        llvm::raw_svector_ostream os(sbuf);
-        unsigned int DIdx = FunctionsToTrack[AS->AllocatorIdx].DeallocatorIdx;
-        os << "Allocated data should be released before another call to "
-           << "the allocator: missing a call to '"
-           << FunctionsToTrack[DIdx].Name
-           << "'.";
-        RangedBugReport *Report = new RangedBugReport(*BT, os.str(), N);
-        Report->addRange(ArgExpr->getSourceRange());
-        C.EmitReport(Report);
+        if (!definitelyReturnedError(AS->RetValue, State, C.getSValBuilder())) {
+          // Remove the value from the state. The new symbol will be added for
+          // tracking when the second allocator is processed in checkPostStmt().
+          State = State->remove<AllocatedData>(V);
+          ExplodedNode *N = C.generateNode(State);
+          if (!N)
+            return;
+          initBugType();
+          llvm::SmallString<128> sbuf;
+          llvm::raw_svector_ostream os(sbuf);
+          unsigned int DIdx = FunctionsToTrack[AS->AllocatorIdx].DeallocatorIdx;
+          os << "Allocated data should be released before another call to "
+              << "the allocator: missing a call to '"
+              << FunctionsToTrack[DIdx].Name
+              << "'.";
+          RangedBugReport *Report = new RangedBugReport(*BT, os.str(), N);
+          Report->addRange(ArgExpr->getSourceRange());
+          C.EmitReport(Report);
+        }
       }
     return;
   }

Modified: cfe/trunk/test/Analysis/keychainAPI.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/keychainAPI.m?rev=137720&r1=137719&r2=137720&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/keychainAPI.m (original)
+++ cfe/trunk/test/Analysis/keychainAPI.m Tue Aug 16 11:30:24 2011
@@ -143,12 +143,22 @@
 } // no-warning
 
 // Make sure we do not report an error if we call free only if password != 0.
-OSStatus testSecKeychainFindGenericPassword(UInt32* passwordLength) {
+// Also, do not report double allocation if first allocation returned an error.
+OSStatus testSecKeychainFindGenericPassword(UInt32* passwordLength,
+                        CFTypeRef keychainOrArray, SecProtocolType protocol, 
+                        SecAuthenticationType authenticationType) {
   OSStatus err;
   SecKeychainItemRef item;
   void *password;
   err = SecKeychainFindGenericPassword(0, 3, "xx", 3, "xx",
                                        passwordLength, &password, &item);
+  if( err == GenericError ) {
+    err = SecKeychainFindInternetPassword(keychainOrArray, 
+                                  16, "server", 16, "domain", 16, "account",
+                                  16, "path", 222, protocol, authenticationType,
+                                  passwordLength, &(password), 0);
+  }
+
   if (err == noErr && password) {
     SecKeychainItemFreeContent(0, password);
   }





More information about the cfe-commits mailing list