Fix for bug 177184 . NSS_CMSDecoder_Cancel might have a leak . And this patch might fix it, or not. But this bug needs to be put to rest.

This commit is contained in:
julien.pierre.bugs%sun.com 2006-08-05 01:19:23 +00:00
parent 2edf37dfb3
commit 6d267dce80
2 changed files with 17 additions and 6 deletions

View File

@ -37,7 +37,7 @@
/*
* cmsutil -- A command to work with CMS data
*
* $Id: cmsutil.c,v 1.52 2004/10/22 22:39:47 julien.pierre.bugs%sun.com Exp $
* $Id: cmsutil.c,v 1.53 2006/08/05 01:19:23 julien.pierre.bugs%sun.com Exp $
*/
#include "nspr.h"
@ -206,6 +206,7 @@ static NSSCMSMessage *
decode(FILE *out, SECItem *input, const struct decodeOptionsStr *decodeOptions)
{
NSSCMSDecoderContext *dcx;
SECStatus rv;
NSSCMSMessage *cmsg;
int nlevels, i;
SECItem sitem = { 0, 0, 0 };
@ -216,7 +217,16 @@ decode(FILE *out, SECItem *input, const struct decodeOptionsStr *decodeOptions)
pwcb, pwcb_arg, /* password callback */
decodeOptions->dkcb, /* decrypt key callback */
decodeOptions->bulkkey);
(void)NSS_CMSDecoder_Update(dcx, (char *)input->data, input->len);
if (dcx == NULL) {
fprintf(stderr, "%s: failed to set up message decoder.\n", progName);
return NULL;
}
rv = NSS_CMSDecoder_Update(dcx, (char *)input->data, input->len);
if (rv != SECSuccess) {
fprintf(stderr, "%s: failed to decode message.\n", progName);
NSS_CMSDecoder_Cancel(dcx);
return NULL;
}
cmsg = NSS_CMSDecoder_Finish(dcx);
if (cmsg == NULL) {
fprintf(stderr, "%s: failed to decode message.\n", progName);

View File

@ -37,7 +37,7 @@
/*
* CMS decoding.
*
* $Id: cmsdecode.c,v 1.8 2004/04/25 15:03:16 gerv%gerv.net Exp $
* $Id: cmsdecode.c,v 1.9 2006/08/05 01:19:23 julien.pierre.bugs%sun.com Exp $
*/
#include "cmslocal.h"
@ -695,10 +695,9 @@ NSS_CMSDecoder_Update(NSSCMSDecoderContext *p7dcx, const char *buf,
void
NSS_CMSDecoder_Cancel(NSSCMSDecoderContext *p7dcx)
{
/* XXXX what about inner decoders? running digests? decryption? */
/* XXXX there's a leak here! */
if (p7dcx->dcx != NULL)
(void)SEC_ASN1DecoderFinish(p7dcx->dcx);
NSS_CMSMessage_Destroy(p7dcx->cmsg);
(void)SEC_ASN1DecoderFinish(p7dcx->dcx);
PORT_Free(p7dcx);
}
@ -736,6 +735,8 @@ NSS_CMSMessage_CreateFromDER(SECItem *DERmessage,
/* first arg(poolp) == NULL => create our own pool */
p7dcx = NSS_CMSDecoder_Start(NULL, cb, cb_arg, pwfn, pwfn_arg,
decrypt_key_cb, decrypt_key_cb_arg);
if (p7dcx == NULL)
return NULL;
NSS_CMSDecoder_Update(p7dcx, (char *)DERmessage->data, DERmessage->len);
return NSS_CMSDecoder_Finish(p7dcx);
}