From cd256adf4029d8f3e3f4f711363933de6efff840 Mon Sep 17 00:00:00 2001 From: "wchang0222%aol.com" Date: Sat, 6 Dec 2003 01:16:50 +0000 Subject: Bugzilla bug 227296: fixed the bug that NSS_CMSAttribute_AddValue adds the address of a stack variable to the attr->values array. Added a new function SECITEM_ArenaDupItem. r=nelsonb. Modified Files: nss/nss.def util/secitem.c util/secitem.h smime/cmsarray.c smime/cmsattr.c --- security/nss/lib/util/secitem.c | 22 +++++++++++++++++++--- security/nss/lib/util/secitem.h | 7 +++++++ 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'security/nss/lib/util') diff --git a/security/nss/lib/util/secitem.c b/security/nss/lib/util/secitem.c index eb4683ca4..daf550d62 100644 --- a/security/nss/lib/util/secitem.c +++ b/security/nss/lib/util/secitem.c @@ -179,6 +179,12 @@ SECITEM_ItemsAreEqual(const SECItem *a, const SECItem *b) SECItem * SECITEM_DupItem(const SECItem *from) +{ + return SECITEM_ArenaDupItem(NULL, from); +} + +SECItem * +SECITEM_ArenaDupItem(PRArenaPool *arena, const SECItem *from) { SECItem *to; @@ -186,12 +192,20 @@ SECITEM_DupItem(const SECItem *from) return(NULL); } - to = (SECItem *)PORT_Alloc(sizeof(SECItem)); + if ( arena != NULL ) { + to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem)); + } else { + to = (SECItem *)PORT_Alloc(sizeof(SECItem)); + } if ( to == NULL ) { return(NULL); } - to->data = (unsigned char *)PORT_Alloc(from->len); + if ( arena != NULL ) { + to->data = (unsigned char *)PORT_ArenaAlloc(arena, from->len); + } else { + to->data = (unsigned char *)PORT_Alloc(from->len); + } if ( to->data == NULL ) { PORT_Free(to); return(NULL); @@ -199,7 +213,9 @@ SECITEM_DupItem(const SECItem *from) to->len = from->len; to->type = from->type; - PORT_Memcpy(to->data, from->data, to->len); + if ( to->len ) { + PORT_Memcpy(to->data, from->data, to->len); + } return(to); } diff --git a/security/nss/lib/util/secitem.h b/security/nss/lib/util/secitem.h index 76a5d16fb..d957ba0eb 100644 --- a/security/nss/lib/util/secitem.h +++ b/security/nss/lib/util/secitem.h @@ -92,6 +92,13 @@ extern SECStatus SECITEM_CopyItem(PRArenaPool *arena, SECItem *to, */ extern SECItem *SECITEM_DupItem(const SECItem *from); +/* +** Allocate an item and copy "from" into it. The item itself and the +** data it points to are both allocated from the arena. If arena is +** NULL, this function is equivalent to SECITEM_DupItem. +*/ +extern SECItem *SECITEM_ArenaDupItem(PRArenaPool *arena, const SECItem *from); + /* ** Free "zap". If freeit is PR_TRUE then "zap" itself is freed. */ -- cgit v1.2.1