]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_keychain/lib/KCCursor.cpp
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / lib / KCCursor.cpp
index b252dd9c961ef45f9f426c7dc4b864f9fa100467..4122197763eed3822b9ea3454b89337ac071181e 100644 (file)
@@ -35,8 +35,9 @@
 #include "Globals.h"
 #include "StorageManager.h"
 #include <Security/SecKeychainItemPriv.h>
-#include <SecBase.h>
+#include <Security/SecBase.h>
 #include <Security/SecBasePriv.h>
+#include <utilities/array_size.h>
 
 using namespace KeychainCore;
 using namespace CssmClient;
@@ -61,8 +62,7 @@ KCCursorImpl::KCCursorImpl(const StorageManager::KeychainList &searchList, SecIt
        mAllFailed(true),
     mDeleteInvalidRecords(false),
     mIsNewKeychain(true),
-       mMutex(Mutex::recursive),
-    mKeychainReadLock(NULL)
+       mMutex(Mutex::recursive)
 {
     recordType(Schema::recordTypeFor(itemClass));
 
@@ -75,8 +75,9 @@ KCCursorImpl::KCCursorImpl(const StorageManager::KeychainList &searchList, SecIt
        for (const SecKeychainAttribute *attr=attrList->attr; attr != end; ++attr)
        {
                const CSSM_DB_ATTRIBUTE_INFO *temp;
-               
-               if (attr->tag <'    ') // ok, is this a key schema?  Handle differently, just because we can...
+
+               // ok, is this a key schema?  Handle differently, just because we can...
+               if (attr->tag <'    ' && attr->tag < array_size(gKeyAttributeLookupTable))
                {
                        temp = gKeyAttributeLookupTable[attr->tag];
                }
@@ -119,8 +120,7 @@ KCCursorImpl::KCCursorImpl(const StorageManager::KeychainList &searchList, const
        mAllFailed(true),
     mDeleteInvalidRecords(false),
     mIsNewKeychain(true),
-       mMutex(Mutex::recursive),
-    mKeychainReadLock(NULL)
+       mMutex(Mutex::recursive)
 {
        if (!attrList) // No additional selectionPredicates: we are done
                return;
@@ -172,11 +172,8 @@ KCCursorImpl::KCCursorImpl(const StorageManager::KeychainList &searchList, const
        }
 }
 
-KCCursorImpl::~KCCursorImpl() throw()
+KCCursorImpl::~KCCursorImpl() _NOEXCEPT
 {
-    if(mKeychainReadLock) {
-        delete mKeychainReadLock;
-    }
 }
 
 //static ModuleNexus<Mutex> gActivationMutex;
@@ -226,6 +223,7 @@ KCCursorImpl::next(Item &item)
             }
 
             Keychain &kc = *mCurrent;
+
             Mutex* mutex = kc->getKeychainMutex();
             StLock<Mutex> _(*mutex);
 
@@ -322,7 +320,6 @@ KCCursorImpl::next(Item &item)
                 }
             }
         }
-        // release the Keychain lock before checking item integrity to avoid deadlock
 
                item = tempItem;
 
@@ -370,18 +367,9 @@ void KCCursorImpl::newKeychain(StorageManager::KeychainList::iterator kcIter) {
         return;
     }
 
-    // Always lose the last keychain's lock
-    if(mKeychainReadLock) {
-        delete mKeychainReadLock;
-        mKeychainReadLock = NULL;
-    }
-
     if(kcIter != mSearchList.end()) {
         (*kcIter)->performKeychainUpgradeIfNeeded();
         (*kcIter)->tickle();
-
-        // Grab a read lock on the keychain
-        mKeychainReadLock = new StReadWriteLock(*((*kcIter)->getKeychainReadWriteLock()), StReadWriteLock::Read);
     }
 
     // Mark down that this function has been called