mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 05:46:58 +00:00
[NSS] NSS_CMSContentInfo_SetContent: only modify cinfo if everything succeeds.
This commit is contained in:
@@ -156,37 +156,40 @@ SECStatus
|
||||
NSS_CMSContentInfo_SetContent(NSSCMSMessage *cmsg, NSSCMSContentInfo *cinfo,
|
||||
SECOidTag type, void *ptr)
|
||||
{
|
||||
SECStatus rv;
|
||||
if (cinfo == NULL || cmsg == NULL) {
|
||||
PORT_SetError(SEC_ERROR_INVALID_ARGS);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
cinfo->contentTypeTag = SECOID_FindOIDByTag(type);
|
||||
if (cinfo->contentTypeTag == NULL) {
|
||||
SECOidData *contentTypeTag = SECOID_FindOIDByTag(type);
|
||||
if (!contentTypeTag) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
/* do not copy the oid, just create a reference */
|
||||
rv = SECITEM_CopyItem(cmsg->poolp, &(cinfo->contentType), &(cinfo->contentTypeTag->oid));
|
||||
SECItem contentType = { siBuffer, NULL, 0 };
|
||||
SECStatus rv = SECITEM_CopyItem(cmsg->poolp, &contentType, &(contentTypeTag->oid));
|
||||
if (rv != SECSuccess) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
cinfo->content.pointer = ptr;
|
||||
|
||||
SECItem *rawContent;
|
||||
if (NSS_CMSType_IsData(type) && ptr) {
|
||||
cinfo->rawContent = ptr;
|
||||
rawContent = ptr;
|
||||
} else {
|
||||
/* as we always have some inner data,
|
||||
* we need to set it to something, just to fool the encoder enough to work on it
|
||||
* and get us into nss_cms_encoder_notify at that point */
|
||||
cinfo->rawContent = SECITEM_AllocItem(cmsg->poolp, NULL, 1);
|
||||
if (cinfo->rawContent == NULL) {
|
||||
PORT_SetError(SEC_ERROR_NO_MEMORY);
|
||||
* we need to set it to something, just to fool the encoder enough to work on it
|
||||
* and get us into nss_cms_encoder_notify at that point */
|
||||
rawContent = SECITEM_AllocItem(cmsg->poolp, NULL, 1);
|
||||
if (!rawContent) {
|
||||
return SECFailure;
|
||||
}
|
||||
}
|
||||
|
||||
cinfo->contentType = contentType;
|
||||
cinfo->content.pointer = ptr;
|
||||
cinfo->contentTypeTag = contentTypeTag;
|
||||
cinfo->rawContent = rawContent;
|
||||
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user