summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornelsonb%netscape.com <devnull@localhost>2004-01-22 02:17:26 +0000
committernelsonb%netscape.com <devnull@localhost>2004-01-22 02:17:26 +0000
commit54fcea1c8f1aa7a261818ba506bdd09df5823963 (patch)
treee7f96a96f7aebcca6a9d2f4d54e4d6646ddfdbcb
parent9d6d1a7b1191ec2caaf206872056722353ccb7a5 (diff)
downloadnss-hg-54fcea1c8f1aa7a261818ba506bdd09df5823963.tar.gz
Fix some erronous code that set SEC_ERROR_NO_MEMORY when there had been
no memory failure. r=relyea. Bug 231566
-rw-r--r--security/nss/cmd/pk12util/pk12util.c56
1 files changed, 25 insertions, 31 deletions
diff --git a/security/nss/cmd/pk12util/pk12util.c b/security/nss/cmd/pk12util/pk12util.c
index f9d392925..011fab29e 100644
--- a/security/nss/cmd/pk12util/pk12util.c
+++ b/security/nss/cmd/pk12util/pk12util.c
@@ -63,7 +63,7 @@ Usage(char *progName)
}
static PRBool
-p12u_OpenExportFile(p12uContext *p12cxt, PRBool fileRead)
+p12u_OpenFile(p12uContext *p12cxt, PRBool fileRead)
{
if(!p12cxt || !p12cxt->filename) {
return PR_FALSE;
@@ -80,7 +80,6 @@ p12u_OpenExportFile(p12uContext *p12cxt, PRBool fileRead)
if(!p12cxt->file) {
p12cxt->error = PR_TRUE;
- PR_SetError(SEC_ERROR_NO_MEMORY, 0);
return PR_FALSE;
}
@@ -88,41 +87,37 @@ p12u_OpenExportFile(p12uContext *p12cxt, PRBool fileRead)
}
static void
-p12u_DestroyExportFileInfo(p12uContext **exp_ptr, PRBool removeFile)
+p12u_DestroyContext(p12uContext **ppCtx, PRBool removeFile)
{
- if(!exp_ptr || !(*exp_ptr)) {
+ if(!ppCtx || !(*ppCtx)) {
return;
}
- if((*exp_ptr)->file != NULL) {
- PR_Close((*exp_ptr)->file);
+ if((*ppCtx)->file != NULL) {
+ PR_Close((*ppCtx)->file);
}
- if((*exp_ptr)->filename != NULL) {
+ if((*ppCtx)->filename != NULL) {
if(removeFile) {
- PR_Delete((*exp_ptr)->filename);
+ PR_Delete((*ppCtx)->filename);
}
- PR_Free((*exp_ptr)->filename);
+ PR_Free((*ppCtx)->filename);
}
- PR_Free(*exp_ptr);
- *exp_ptr = NULL;
+ PR_Free(*ppCtx);
+ *ppCtx = NULL;
}
static p12uContext *
-p12u_InitFile(PRBool fileImport, char *filename)
+p12u_InitContext(PRBool fileImport, char *filename)
{
p12uContext *p12cxt;
PRBool fileExist;
- if(fileImport)
- fileExist = PR_TRUE;
- else
- fileExist = PR_FALSE;
+ fileExist = fileImport;
- p12cxt = (p12uContext *)PORT_ZAlloc(sizeof(p12uContext));
+ p12cxt = PORT_ZNew(p12uContext);
if(!p12cxt) {
- PR_SetError(SEC_ERROR_NO_MEMORY, 0);
return NULL;
}
@@ -130,9 +125,8 @@ p12u_InitFile(PRBool fileImport, char *filename)
p12cxt->errorValue = 0;
p12cxt->filename = strdup(filename);
- if(!p12u_OpenExportFile(p12cxt, fileImport)) {
- PR_SetError(p12cxt->errorValue, 0);
- p12u_DestroyExportFileInfo(&p12cxt, PR_FALSE);
+ if(!p12u_OpenFile(p12cxt, fileImport)) {
+ p12u_DestroyContext(&p12cxt, PR_FALSE);
return NULL;
}
@@ -373,9 +367,9 @@ P12U_ImportPKCS12Object(char *in_file, PK11SlotInfo *slot,
goto loser;
}
- p12cxt = p12u_InitFile(PR_TRUE, in_file);
+ p12cxt = p12u_InitContext(PR_TRUE, in_file);
if(!p12cxt) {
- SECU_PrintError(progName,"Initialization failed: %s", in_file);
+ SECU_PrintError(progName,"File Open failed: %s", in_file);
pk12uErrno = PK12UERR_INIT_FILE;
goto loser;
}
@@ -483,7 +477,7 @@ loser:
if (p12dcx) {
SEC_PKCS12DecoderFinish(p12dcx);
}
- p12u_DestroyExportFileInfo(&p12cxt, PR_FALSE);
+ p12u_DestroyContext(&p12cxt, PR_FALSE);
if (uniPwitem.data) {
SECITEM_ZfreeItem(&uniPwitem, PR_FALSE);
@@ -580,7 +574,7 @@ P12U_ExportPKCS12Object(char *nn, char *outfile, PK11SlotInfo *inSlot,
goto loser;
}
- p12cxt = p12u_InitFile(PR_FALSE, outfile);
+ p12cxt = p12u_InitContext(PR_FALSE, outfile);
if(!p12cxt) {
SECU_PrintError(progName,"Initialization failed: %s", outfile);
pk12uErrno = PK12UERR_INIT_FILE;
@@ -660,7 +654,7 @@ P12U_ExportPKCS12Object(char *nn, char *outfile, PK11SlotInfo *inSlot,
goto loser;
}
- p12u_DestroyExportFileInfo(&p12cxt, PR_FALSE);
+ p12u_DestroyContext(&p12cxt, PR_FALSE);
SECITEM_ZfreeItem(pwitem, PR_TRUE);
fprintf(stdout, "%s: PKCS12 EXPORT SUCCESSFUL\n", progName);
SEC_PKCS12DestroyExportContext(p12ecx);
@@ -681,7 +675,7 @@ loser:
if (p12FilePw)
PR_Free(p12FilePw->data);
- p12u_DestroyExportFileInfo(&p12cxt, PR_TRUE);
+ p12u_DestroyContext(&p12cxt, PR_TRUE);
if(pwitem) {
SECITEM_ZfreeItem(pwitem, PR_TRUE);
}
@@ -781,8 +775,8 @@ main(int argc, char **argv)
pk12_debugging = pk12util.options[opt_Debug].activated;
- if (pk12util.options[opt_Import].activated &&
- pk12util.options[opt_Export].activated) {
+ if (pk12util.options[opt_Import].activated +
+ pk12util.options[opt_Export].activated != 1) {
Usage(progName);
}
@@ -851,7 +845,7 @@ main(int argc, char **argv)
done:
if (slot) PK11_FreeSlot(slot);
if (NSS_Shutdown() != SECSuccess) {
- exit(1);
+ pk12uErrno = 1;
}
- exit(pk12uErrno);
+ return pk12uErrno;
}