diff options
author | wtchang%redhat.com <devnull@localhost> | 2006-04-24 23:48:05 +0000 |
---|---|---|
committer | wtchang%redhat.com <devnull@localhost> | 2006-04-24 23:48:05 +0000 |
commit | b38f093f56dd11c1486081d23dc676a58a8404be (patch) | |
tree | 7b7992fd85a45917eab4a5561f2b43e89874277e | |
parent | 27a54d8584ba00cbc34dca4054689cbd973c6e29 (diff) | |
download | nss-hg-b38f093f56dd11c1486081d23dc676a58a8404be.tar.gz |
Bugzilla Bug 320336: SECITEM_AllocItem should return a NULL pointer if the
allocation of its 'data' buffer fails. r=nelson. This checkin fixed bug
333405 as a byproduct.
Modified files: secitem.c secitem.h
Tag: NSS_3_11_BRANCH
-rw-r--r-- | security/nss/lib/util/secitem.c | 18 | ||||
-rw-r--r-- | security/nss/lib/util/secitem.h | 3 |
2 files changed, 13 insertions, 8 deletions
diff --git a/security/nss/lib/util/secitem.c b/security/nss/lib/util/secitem.c index 71009143c..20eaecd0c 100644 --- a/security/nss/lib/util/secitem.c +++ b/security/nss/lib/util/secitem.c @@ -65,17 +65,17 @@ SECITEM_AllocItem(PRArenaPool *arena, SECItem *item, unsigned int len) goto loser; } } else { - PORT_Assert(item->data == NULL); result = item; } result->len = 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 (result->data == NULL && len) { + goto loser; } if (mark) { @@ -96,6 +96,10 @@ loser: if (result != NULL) { SECITEM_FreeItem(result, (item == NULL) ? PR_TRUE : PR_FALSE); } + /* + * If item is not NULL, the above has set item->data and + * item->len to 0. + */ } return(NULL); } diff --git a/security/nss/lib/util/secitem.h b/security/nss/lib/util/secitem.h index b73083f2b..fee905c2f 100644 --- a/security/nss/lib/util/secitem.h +++ b/security/nss/lib/util/secitem.h @@ -53,7 +53,8 @@ SEC_BEGIN_PROTOS ** Allocate an item. If "arena" is not NULL, then allocate from there, ** otherwise allocate from the heap. If "item" is not NULL, allocate ** only the data for the item, not the item itself. The item structure -** is allocated zero-filled; the data buffer is not zeroed. +** is allocated zero-filled; the data buffer is not zeroed. The caller +** is responsible for initializing the type field of the item. ** ** The resulting item is returned; NULL if any error occurs. ** |