if (certreq != NULL) { certreq->arena = arena;  rv = DER_SetUInteger(arena, &certreq->version, SEC_CERTIFICATE_REQUEST_VERSION); if (rv != SECSuccess)
certreq->arena = arena;  rv = DER_SetUInteger(arena, &certreq->version, SEC_CERTIFICATE_REQUEST_VERSION); if (rv != SECSuccess) goto loser;  rv = CERT_CopyName(arena, &certreq->subject, subject); if (rv != SECSuccess) goto loser;  rv = SECKEY_CopySubjectPublicKeyInfo(arena, &certreq->subjectPublicKeyInfo, spki); if (rv != SECSuccess) goto loser;  certreq->attributes = PORT_ArenaZNewArray(arena, CERTAttribute*, 2); if(!certreq->attributes) goto loser;   if (!attributes || !attributes[0]) {  certreq->attributes[0] = NULL; return certreq; }   attribute = PORT_ArenaZNew(arena, CERTAttribute); if (!attribute) goto loser;  oidData = SECOID_FindOIDByTag( SEC_OID_PKCS9_EXTENSION_REQUEST ); PORT_Assert(oidData); if (!oidData) goto loser; rv = SECITEM_CopyItem(arena, &attribute->attrType, &oidData->oid); if (rv != SECSuccess) goto loser;  for (i = 0; attributes[i] != NULL ; i++) ; attribute->attrValue = PORT_ArenaZNewArray(arena, SECItem *, i+1); if (!attribute->attrValue) goto loser;   for (i = 0; attributes[i]; i++) {  attribute->attrValue[i] = SECITEM_ArenaDupItem(arena, attributes[i]); if(!attribute->attrValue[i])
CERT_CreateCertificateRequest(CERTName *subject,			     CERTSubjectPublicKeyInfo *spki,			     SECItem **attributes){    CERTCertificateRequest *certreq;    PRArenaPool *arena;    SECStatus rv;    arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);    if ( arena == NULL ) {	return NULL;    }        certreq = (CERTCertificateRequest *)			PORT_ArenaZAlloc(arena, sizeof(CERTCertificateRequest));    if (certreq != NULL) {	certreq->arena = arena;		rv = DER_SetUInteger(arena, &certreq->version,			     SEC_CERTIFICATE_REQUEST_VERSION);	if (rv != SECSuccess)	    goto loser;	rv = CERT_CopyName(arena, &certreq->subject, subject);	if (rv != SECSuccess)	    goto loser;	rv = SECKEY_CopySubjectPublicKeyInfo(arena,					  &certreq->subjectPublicKeyInfo,					  spki);	if (rv != SECSuccess)	    goto loser;	/* Copy over attribute information */	if (attributes) {	    int i = 0;	    /* allocate space for attributes */	    while(attributes[i] != NULL) i++;	    certreq->attributes = PORT_ArenaZNewArray(arena,CERTAttribute*,i+1);	    if(!certreq->attributes) {		goto loser;	    }	    /* copy attributes */	    i = 0;	    while(attributes[i]) {		/*		** Attributes are a SetOf Attribute which implies		** lexigraphical ordering.  It is assumes that the		** attributes are passed in sorted.  If we need to		** add functionality to sort them, there is an		** example in the PKCS 7 code.		*/		certreq->attributes[i] = (SECItem*)PORT_ArenaZAlloc(arena, 							  	    sizeof(SECItem));		if(!certreq->attributes[i]) {		    goto loser;		};		rv = SECITEM_CopyItem(arena, certreq->attributes[i], 				      attributes[i]);		if (rv != SECSuccess) {		    goto loser;		}		i++;	    }	    certreq->attributes[i] = NULL;	} else {	    /*	     ** Invent empty attribute information. According to the	     ** pkcs#10 spec, attributes has this ASN.1 type:	     **	     ** attributes [0] IMPLICIT Attributes	     ** 	     ** Which means, we should create a NULL terminated list	     ** with the first entry being NULL;	     */	    certreq->attributes = (SECItem**)PORT_ArenaZAlloc(arena, sizeof(SECItem *));	    if(!certreq->attributes) {		goto loser;	    }	    certreq->attributes[0] = NULL;	}     } else {	PORT_FreeArena(arena, PR_FALSE);    }    return certreq;loser:    CERT_DestroyCertificateRequest(certreq);    return NULL;}