X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..refs/heads/master:/OSX/libsecurity_cdsa_utilities/lib/cssmdb.h diff --git a/OSX/libsecurity_cdsa_utilities/lib/cssmdb.h b/OSX/libsecurity_cdsa_utilities/lib/cssmdb.h index 5ecb5a29..be227a3b 100644 --- a/OSX/libsecurity_cdsa_utilities/lib/cssmdb.h +++ b/OSX/libsecurity_cdsa_utilities/lib/cssmdb.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include @@ -199,8 +199,13 @@ public: CssmDlDbHandle *handles() const { return CssmDlDbHandle::overlay(DLDBHandle); } CssmDlDbHandle * &handles() { return CssmDlDbHandle::overlayVar(DLDBHandle); } - CssmDlDbHandle &operator [] (uint32 ix) const - { assert(ix < count()); return CssmDlDbHandle::overlay(DLDBHandle[ix]); } + CssmDlDbHandle &operator [] (uint32 ix) const { + if (ix >= count()) { + secemergency("CssmDlDbList: attempt to index beyond bounds"); + abort(); + } + return CssmDlDbHandle::overlay(DLDBHandle[ix]); + } void setDlDbList(uint32 n, CSSM_DL_DB_HANDLE *list) { count() = n; handles() = CssmDlDbHandle::overlay(list); } @@ -215,9 +220,7 @@ class CssmDLPolyData public: CssmDLPolyData(const CSSM_DATA &data, CSSM_DB_ATTRIBUTE_FORMAT format) : mData(CssmData::overlay(data)) -#ifndef NDEBUG , mFormat(format) -#endif {} // @@@ Don't use assert, but throw an exception. @@ -264,9 +267,7 @@ public: private: const CssmData &mData; -#ifndef NDEBUG CSSM_DB_ATTRIBUTE_FORMAT mFormat; -#endif }; @@ -345,8 +346,13 @@ public: { return CssmDbAttributeInfo::overlayVar(AttributeInfo); } CssmDbAttributeInfo *attributes() const { return CssmDbAttributeInfo::overlay(AttributeInfo); } - CssmDbAttributeInfo &at(uint32 ix) const - { assert(ix < size()); return attributes()[ix]; } + CssmDbAttributeInfo &at(uint32 ix) const { + if (ix >= size()) { + secemergency("CssmDbRecordAttributeInfo: attempt to index beyond bounds"); + abort(); + } + return attributes()[ix]; + } CssmDbAttributeInfo &operator [] (uint32 ix) const { return at(ix); } }; @@ -481,8 +487,13 @@ public: { return CssmDbAttributeData::overlay(AttributeData); } // Attributes by position - CssmDbAttributeData &at(unsigned int ix) const - { assert(ix < size()); return attributes()[ix]; } + CssmDbAttributeData &at(unsigned int ix) const { + if (ix >= size()) { + secemergency("CssmDbRecordAttributeData: attempt to index beyond bounds"); + abort(); + } + return attributes()[ix]; + } CssmDbAttributeData &operator [] (unsigned int ix) const { return at(ix); } @@ -518,12 +529,16 @@ public: CssmDbAttributeData &add(const CSSM_DB_ATTRIBUTE_INFO &info); CssmDbAttributeData &add(const CSSM_DB_ATTRIBUTE_INFO &info, const CssmPolyData &value); + // Take the attributes from the object, and overlay them onto this one + void updateWith(const CssmAutoDbRecordAttributeData* newValues); + // So clients can pass this as the allocator argument to add() operator Allocator &() const { return mValueAllocator; } + + CssmDbAttributeData* findAttribute (const CSSM_DB_ATTRIBUTE_INFO &info); private: Allocator &mValueAllocator; - - CssmDbAttributeData* findAttribute (const CSSM_DB_ATTRIBUTE_INFO &info); + CssmDbAttributeData& getAttributeReference (const CSSM_DB_ATTRIBUTE_INFO &info); }; @@ -592,8 +607,13 @@ public: CssmSelectionPredicate *predicates() const { return CssmSelectionPredicate::overlay(SelectionPredicate); } - CssmSelectionPredicate &at(uint32 ix) const - { assert(ix < size()); return predicates()[ix]; } + CssmSelectionPredicate &at(uint32 ix) const { + if (ix >= size()) { + secemergency("CssmDbRecordAttributeData: attempt to index beyond bounds"); + abort(); + } + return predicates()[ix]; + } CssmSelectionPredicate &operator[] (uint32 ix) const { return at(ix); } @@ -662,6 +682,8 @@ public: const CSSM_NET_ADDRESS *location = NULL) : mImpl(new Impl(CssmSubserviceUid(guid, NULL, ssid, sstype), name, location)) { } + DLDbIdentifier(const DLDbIdentifier& i) : mImpl(i.mImpl) {} + // Conversion Operators bool operator !() const { return !mImpl; } operator bool() const { return mImpl; } @@ -725,7 +747,10 @@ struct DLDbFlatIdentifier { address(const_cast(ident.dbLocation())) { } - operator DLDbIdentifier () { return DLDbIdentifier(*uid, name, address); } + operator DLDbIdentifier () { + DLDbIdentifier db(*uid, name, address); + return db; + } }; template