PORT_ArenaAlloc(arena, nemailAddrs * sizeof(char *));
PORT_ArenaAlloc(arena, entry->nemailAddrs * sizeof(char *));
DecodeDBSubjectEntry(certDBEntrySubject *entry, SECItem *dbentry,		     SECItem *derSubject){    unsigned int ncerts;    PRArenaPool *arena;    unsigned int len, itemlen;    unsigned char *tmpbuf;    unsigned char *end;    unsigned int i;    SECStatus rv;    unsigned int keyidoff;    unsigned int nnlen, eaddrlen;    unsigned int nemailAddrs = 0;    unsigned int stdlen;        arena = entry->common.arena;    rv = SECITEM_CopyItem(arena, &entry->derSubject, derSubject);    if ( rv != SECSuccess ) {	goto loser;    }    /* is record long enough for header? */    if ( dbentry->len < DB_SUBJECT_ENTRY_HEADER_LEN ) {	PORT_SetError(SEC_ERROR_BAD_DATABASE);	goto loser;    }        entry->ncerts = ncerts = ( ( dbentry->data[0] << 8 ) | dbentry->data[1] );    nnlen = ( ( dbentry->data[2] << 8 ) | dbentry->data[3] );    eaddrlen = ( ( dbentry->data[4] << 8 ) | dbentry->data[5] );    stdlen = ncerts * 4 + DB_SUBJECT_ENTRY_HEADER_LEN + nnlen + eaddrlen;    if ( dbentry->len < stdlen) {	PORT_SetError(SEC_ERROR_BAD_DATABASE);	goto loser;    }        entry->certKeys = (SECItem *)PORT_ArenaAlloc(arena,						 sizeof(SECItem) * ncerts);    entry->keyIDs = (SECItem *)PORT_ArenaAlloc(arena,					       sizeof(SECItem) * ncerts);    if ( ( entry->certKeys == NULL ) || ( entry->keyIDs == NULL ) ) {	PORT_SetError(SEC_ERROR_NO_MEMORY);	goto loser;    }    if ( nnlen > 1 ) { /* null terminator is stored */	entry->nickname = (char *)PORT_ArenaAlloc(arena, nnlen);	if ( entry->nickname == NULL ) {	    PORT_SetError(SEC_ERROR_NO_MEMORY);	    goto loser;	}	PORT_Memcpy(entry->nickname,		    &dbentry->data[DB_SUBJECT_ENTRY_HEADER_LEN],		    nnlen);    } else {	entry->nickname = NULL;    }    /* if we have an old style email entry, there is only one */        entry->nemailAddrs = 0;    if ( eaddrlen > 1 ) { /* null terminator is stored */	entry->emailAddrs = (char **)PORT_ArenaAlloc(arena, sizeof(char *));	if ( entry->emailAddrs == NULL ) {	    PORT_SetError(SEC_ERROR_NO_MEMORY);	    goto loser;	}	entry->emailAddrs[0] = (char *)PORT_ArenaAlloc(arena, eaddrlen);	if ( entry->emailAddrs[0] == NULL ) {	    PORT_SetError(SEC_ERROR_NO_MEMORY);	    goto loser;	}	PORT_Memcpy(entry->emailAddrs[0],		    &dbentry->data[DB_SUBJECT_ENTRY_HEADER_LEN+nnlen],		    eaddrlen);	 entry->nemailAddrs = 1;    } else {	entry->emailAddrs = NULL;    }        /* collect the lengths of the certKeys and keyIDs, and total the     * overall length.     */    keyidoff = DB_SUBJECT_ENTRY_HEADER_LEN + nnlen + eaddrlen;    len = keyidoff + 4 * ncerts;    tmpbuf = &dbentry->data[0];        for ( i = 0; i < ncerts; i++ ) {	itemlen = ( tmpbuf[keyidoff + 2*i] << 8 ) | tmpbuf[keyidoff + 1 + 2*i] ;	len += itemlen;	entry->certKeys[i].len = itemlen;	itemlen = ( tmpbuf[keyidoff + 2*ncerts + 2*i] << 8 ) |	    tmpbuf[keyidoff + 1 + 2*ncerts + 2*i] ;	len += itemlen;	entry->keyIDs[i].len = itemlen;    }        /* is database entry correct length? */    if ( len > dbentry->len ){	PORT_SetError(SEC_ERROR_BAD_DATABASE);	goto loser;    }        tmpbuf = &tmpbuf[keyidoff + 4*ncerts];    for ( i = 0; i < ncerts; i++ ) {	entry->certKeys[i].data =	    (unsigned char *)PORT_ArenaAlloc(arena, entry->certKeys[i].len);	if ( entry->certKeys[i].data == NULL ) {	    PORT_SetError(SEC_ERROR_NO_MEMORY);	    goto loser;	}	PORT_Memcpy(entry->certKeys[i].data, tmpbuf, entry->certKeys[i].len);	tmpbuf = &tmpbuf[entry->certKeys[i].len];    }    for ( i = 0; i < ncerts; i++ ) {	entry->keyIDs[i].data =	    (unsigned char *)PORT_ArenaAlloc(arena, entry->keyIDs[i].len);	if ( entry->keyIDs[i].data == NULL ) {	    PORT_SetError(SEC_ERROR_NO_MEMORY);	    goto loser;	}	PORT_Memcpy(entry->keyIDs[i].data, tmpbuf, entry->keyIDs[i].len);	tmpbuf = &tmpbuf[entry->keyIDs[i].len];    }    end = &dbentry->data[dbentry->len];    if ((eaddrlen == 0) && (tmpbuf+1 < end)) {	/* read in the additional email addresses */	entry->nemailAddrs = tmpbuf[0] << 8 | tmpbuf[1];	entry->emailAddrs = (char **)		PORT_ArenaAlloc(arena, nemailAddrs * sizeof(char *));	if (entry->emailAddrs == NULL) {	    PORT_SetError(SEC_ERROR_NO_MEMORY);	    goto loser;	}	for (i=0; i < entry->nemailAddrs; i++) {	    int nameLen = tmpbuf[0] << 8 | tmpbuf[1];	    entry->emailAddrs[i] = PORT_ArenaAlloc(arena,nameLen);	    if (entry->emailAddrs == NULL) {	        PORT_SetError(SEC_ERROR_NO_MEMORY);	        goto loser;	    }	    PORT_Memcpy(entry->emailAddrs[i],&tmpbuf[2],nameLen);	    tmpbuf += 2 + nameLen;	}    }            return(SECSuccess);loser:    return(SECFailure);}