X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..07691282a056c4efea71e1e505527601e8cc166b:/OSX/libsecurity_smime/lib/secitem.c?ds=sidebyside diff --git a/OSX/libsecurity_smime/lib/secitem.c b/OSX/libsecurity_smime/lib/secitem.c index 59070c65..1eea11ed 100644 --- a/OSX/libsecurity_smime/lib/secitem.c +++ b/OSX/libsecurity_smime/lib/secitem.c @@ -3,25 +3,25 @@ * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ - * + * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. - * + * * The Original Code is the Netscape security libraries. - * + * * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are + * Communications Corporation. Portions created by Netscape are * Copyright (C) 1994-2000 Netscape Communications Corporation. All * Rights Reserved. - * + * * Contributor(s): - * + * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the - * "GPL"), in which case the provisions of the GPL are applicable - * instead of those above. If you wish to allow use of your + * "GPL"), in which case the provisions of the GPL are applicable + * instead of those above. If you wish to allow use of your * version of this file only under the terms of the GPL and not to * allow others to use your version of this file under the MPL, * indicate your decision by deleting the provisions above and @@ -46,89 +46,79 @@ SECITEM_AllocItem(PRArenaPool *arena, SECItem *item, size_t len) void *mark = NULL; if (arena != NULL) { - mark = PORT_ArenaMark(arena); + mark = PORT_ArenaMark(arena); } if (item == NULL) { - if (arena != NULL) { - result = PORT_ArenaZAlloc(arena, sizeof(SECItem)); - } else { - result = PORT_ZAlloc(sizeof(SECItem)); - } - if (result == NULL) { - goto loser; - } + if (arena != NULL) { + result = PORT_ArenaZAlloc(arena, sizeof(SECItem)); + } else { + result = PORT_ZAlloc(sizeof(SECItem)); + } + if (result == NULL) { + goto loser; + } } else { - PORT_Assert(item->Data == NULL); - result = item; + PORT_Assert(item->Data == NULL); + result = item; } result->Length = len; if (len) { - if (arena != NULL) { - result->Data = PORT_ArenaAlloc(arena, len); - } else { - result->Data = PORT_Alloc(len); - } + if (arena != NULL) { + result->Data = PORT_ArenaAlloc(arena, len); + } else { + result->Data = PORT_Alloc(len); + } } if (mark) { - PORT_ArenaUnmark(arena, mark); + PORT_ArenaUnmark(arena, mark); } return(result); loser: - if ( arena != NULL ) { - if (mark) { - PORT_ArenaRelease(arena, mark); - } - if (item != NULL) { - item->Data = NULL; - item->Length = 0; - } - } else { - if (result != NULL) { - SECITEM_FreeItem(result, (item == NULL) ? PR_TRUE : PR_FALSE); - } + if (arena != NULL && mark) { + PORT_ArenaRelease(arena, mark); } return(NULL); } SECStatus SECITEM_ReallocItem(PRArenaPool *arena, SECItem *item, unsigned int oldlen, - unsigned int newlen) + unsigned int newlen) { PORT_Assert(item != NULL); if (item == NULL) { - /* XXX Set error. But to what? */ - return SECFailure; + /* XXX Set error. But to what? */ + return SECFailure; } /* * If no old length, degenerate to just plain alloc. */ if (oldlen == 0) { - PORT_Assert(item->Data == NULL || item->Length == 0); - if (newlen == 0) { - /* Nothing to do. Weird, but not a failure. */ - return SECSuccess; - } - item->Length = newlen; - if (arena != NULL) { - item->Data = PORT_ArenaAlloc(arena, newlen); - } else { - item->Data = PORT_Alloc(newlen); - } + PORT_Assert(item->Data == NULL || item->Length == 0); + if (newlen == 0) { + /* Nothing to do. Weird, but not a failure. */ + return SECSuccess; + } + item->Length = newlen; + if (arena != NULL) { + item->Data = PORT_ArenaAlloc(arena, newlen); + } else { + item->Data = PORT_Alloc(newlen); + } } else { - if (arena != NULL) { - item->Data = PORT_ArenaGrow(arena, item->Data, oldlen, newlen); - } else { - item->Data = PORT_Realloc(item->Data, newlen); - } + if (arena != NULL) { + item->Data = PORT_ArenaGrow(arena, item->Data, oldlen, newlen); + } else { + item->Data = PORT_Realloc(item->Data, newlen); + } } if (item->Data == NULL) { - return SECFailure; + return SECFailure; } return SECSuccess; @@ -141,16 +131,16 @@ SECITEM_CompareItem(const SECItem *a, const SECItem *b) SECComparison rv; m = ( ( a->Length < b->Length ) ? a->Length : b->Length ); - + rv = (SECComparison) PORT_Memcmp(a->Data, b->Data, m); if (rv) { - return rv; + return rv; } if (a->Length < b->Length) { - return SECLessThan; + return SECLessThan; } if (a->Length == b->Length) { - return SECEqual; + return SECEqual; } return SECGreaterThan; } @@ -161,10 +151,10 @@ SECITEM_ItemsAreEqual(const SECItem *a, const SECItem *b) if (a->Length != b->Length) return PR_FALSE; if (!a->Length) - return PR_TRUE; + return PR_TRUE; if (!a->Data || !b->Data) { /* avoid null pointer crash. */ - return (Boolean)(a->Data == b->Data); + return (Boolean)(a->Data == b->Data); } return (Boolean)!PORT_Memcmp(a->Data, b->Data, a->Length); } @@ -181,32 +171,32 @@ SECITEM_ArenaDupItem(PRArenaPool *arena, const SECItem *from) SECItem *to; if ( from == NULL ) { - return(NULL); + return(NULL); } if ( arena != NULL ) { - to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem)); + to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem)); } else { - to = (SECItem *)PORT_Alloc(sizeof(SECItem)); + to = (SECItem *)PORT_Alloc(sizeof(SECItem)); } if ( to == NULL ) { - return(NULL); + return(NULL); } if ( arena != NULL ) { - to->Data = (unsigned char *)PORT_ArenaAlloc(arena, from->Length); + to->Data = (unsigned char *)PORT_ArenaAlloc(arena, from->Length); } else { - to->Data = (unsigned char *)PORT_Alloc(from->Length); + to->Data = (unsigned char *)PORT_Alloc(from->Length); } if ( to->Data == NULL ) { - PORT_Free(to); - return(NULL); + PORT_Free(to); + return(NULL); } to->Length = from->Length; // to->type = from->type; if ( to->Length ) { - PORT_Memcpy(to->Data, from->Data, to->Length); + PORT_Memcpy(to->Data, from->Data, to->Length); } return(to); @@ -217,20 +207,20 @@ SECITEM_CopyItem(PRArenaPool *arena, SECItem *to, const SECItem *from) { // to->type = from->type; if (from->Data && from->Length) { - if ( arena ) { - to->Data = (unsigned char*) PORT_ArenaAlloc(arena, from->Length); - } else { - to->Data = (unsigned char*) PORT_Alloc(from->Length); - } - - if (!to->Data) { - return SECFailure; - } - PORT_Memcpy(to->Data, from->Data, from->Length); - to->Length = from->Length; + if ( arena ) { + to->Data = (unsigned char*) PORT_ArenaAlloc(arena, from->Length); + } else { + to->Data = (unsigned char*) PORT_Alloc(from->Length); + } + + if (!to->Data) { + return SECFailure; + } + PORT_Memcpy(to->Data, from->Data, from->Length); + to->Length = from->Length; } else { - to->Data = 0; - to->Length = 0; + to->Data = 0; + to->Length = 0; } return SECSuccess; } @@ -239,12 +229,12 @@ void SECITEM_FreeItem(SECItem *zap, Boolean freeit) { if (zap) { - PORT_Free(zap->Data); - zap->Data = 0; - zap->Length = 0; - if (freeit) { - PORT_Free(zap); - } + PORT_Free(zap->Data); + zap->Data = 0; + zap->Length = 0; + if (freeit) { + PORT_Free(zap); + } } } @@ -252,12 +242,12 @@ void SECITEM_ZfreeItem(SECItem *zap, Boolean freeit) { if (zap) { - PORT_ZFree(zap->Data, zap->Length); - zap->Data = 0; - zap->Length = 0; - if (freeit) { - PORT_ZFree(zap, sizeof(SECItem)); - } + PORT_ZFree(zap->Data, zap->Length); + zap->Data = 0; + zap->Length = 0; + if (freeit) { + PORT_ZFree(zap, sizeof(SECItem)); + } } } @@ -279,12 +269,12 @@ SECITEM_Hash ( const void *key) PRUint8 *data = (PRUint8 *)item->Data; PRUint32 i; PRUint8 *rvc = (PRUint8 *)&rv; - + for( i = 0; i < item->Length; i++ ) { rvc[ i % sizeof(rv) ] ^= *data; data++; } - + return rv; } @@ -299,6 +289,6 @@ SECITEM_HashCompare ( const void *k1, const void *k2) { const SECItem *i1 = (const SECItem *)k1; const SECItem *i2 = (const SECItem *)k2; - + return SECITEM_ItemsAreEqual(i1,i2); }