if (nss_cms_before_data(p7dcx) != SECSuccess) {
SEC_ASN1DecoderClearFilterProc(p7dcx->dcx); /* stop all processing */
p7dcx->error = PORT_GetError();
+ PORT_SetError(0); // Clean the thread error since we've returned the error
}
}
if (after && dest == &(cinfo->rawContent)) {
/* we're right after of the data */
- if (nss_cms_after_data(p7dcx) != SECSuccess)
+ if (nss_cms_after_data(p7dcx) != SECSuccess) {
p7dcx->error = PORT_GetError();
+ PORT_SetError(0); // Clean the thread error since we've returned the error
+ }
/* we don't need to see the contents anymore */
SEC_ASN1DecoderClearFilterProc(p7dcx->dcx);
cinfo->content.pointer = childp7dcx->content.pointer;
/* start the child decoder */
- childp7dcx->dcx = SEC_ASN1DecoderStart(poolp, childp7dcx->content.pointer, template, NULL);
+ childp7dcx->dcx = SEC_ASN1DecoderStart(poolp, childp7dcx->content.pointer, template, NULL, 0);
if (childp7dcx->dcx == NULL)
goto loser;
nss_cms_after_end(SecCmsDecoderRef p7dcx)
{
OSStatus rv;
- PLArenaPool *poolp;
-
- poolp = p7dcx->cmsg->poolp;
switch (p7dcx->type) {
case SEC_OID_PKCS7_SIGNED_DATA:
data, len, final);
if (rv != SECSuccess) {
p7dcx->error = PORT_GetError();
+ PORT_SetError(0); // Clean the thread error since we've returned the error
goto loser;
}
SecCmsMessageRef cmsg;
OSStatus result;
+ /* Clear the thread error to clean up dirty threads */
+ PORT_SetError(0);
+
cmsg = SecCmsMessageCreate(pool);
if (cmsg == NULL)
goto loser;
goto loser;
}
- p7dcx->dcx = SEC_ASN1DecoderStart(cmsg->poolp, cmsg, SecCmsMessageTemplate, NULL);
+ p7dcx->dcx = SEC_ASN1DecoderStart(cmsg->poolp, cmsg, SecCmsMessageTemplate, NULL, 0);
if (p7dcx->dcx == NULL) {
PORT_Free (p7dcx);
SecCmsMessageDestroy(cmsg);
loser:
result = PORT_GetError();
+ PORT_SetError(0); // Clean the thread error since we've returned the error
return result;
}
OSStatus
SecCmsDecoderUpdate(SecCmsDecoderRef p7dcx, const void *buf, CFIndex len)
{
+ if (!p7dcx) {
+ return errSecParam;
+ }
+
if (p7dcx->dcx != NULL && p7dcx->error == 0) { /* if error is set already, don't bother */
if (SEC_ASN1DecoderUpdate (p7dcx->dcx, buf, len) != SECSuccess) {
p7dcx->error = PORT_GetError();
(void) SEC_ASN1DecoderFinish (p7dcx->dcx);
p7dcx->dcx = NULL;
}
- PORT_SetError (p7dcx->error);
+ PORT_SetError (0); // Clean the thread error since we've returned the error
return p7dcx->error;
}
void
SecCmsDecoderDestroy(SecCmsDecoderRef p7dcx)
{
- /* XXXX what about inner decoders? running digests? decryption? */
- /* XXXX there's a leak here! */
- SecCmsMessageDestroy(p7dcx->cmsg);
- if (p7dcx->dcx)
+ /* SecCmsMessageDestroy frees inner decoders and digests. */
+ if (p7dcx->cmsg) {
+ SecCmsMessageDestroy(p7dcx->cmsg);
+ }
+ if (p7dcx->dcx) {
(void)SEC_ASN1DecoderFinish(p7dcx->dcx);
+ }
+ /* Clear out references */
+ p7dcx->cmsg = NULL;
+ p7dcx->dcx = NULL;
+ p7dcx->childp7dcx = NULL;
PORT_Free(p7dcx);
}
if (p7dcx->dcx == NULL || SEC_ASN1DecoderFinish(p7dcx->dcx) != SECSuccess ||
nss_cms_after_end(p7dcx) != SECSuccess)
{
- SecCmsMessageDestroy(cmsg); /* needs to get rid of pool if it's ours */
+ if (p7dcx->cmsg) {
+ SecCmsMessageDestroy(cmsg); /* needs to get rid of pool if it's ours */
+ }
result = PORT_GetError();
goto loser;
}
result = noErr;
loser:
+ /* Clear out references */
+ p7dcx->cmsg = NULL;
+ p7dcx->dcx = NULL;
+ p7dcx->childp7dcx = NULL;
PORT_Free(p7dcx);
+ PORT_SetError(0); // Clean the thread error since we've returned the error
return result;
}