Skip to content

Commit

Permalink
Bug 1307531 - fix derdump leaks, r=ttaubert
Browse files Browse the repository at this point in the history
--HG--
extra : rebase_source : 46d2b032558ba2e197b9873d0531a94d23e1db1a
extra : amend_source : 4b6815cc95e5f20899d33fbd1c463e22f4ae9204
  • Loading branch information
franziskuskiefer committed Oct 4, 2016
1 parent 8f45f4c commit 52d3036
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions cmd/derdump/derdump.c
Expand Up @@ -34,12 +34,13 @@ main(int argc, char **argv)
char *progName;
FILE *outFile;
PRFileDesc *inFile;
SECItem der;
SECItem der = { siBuffer, NULL, 0 };
SECStatus rv;
PRInt16 xp_error;
PRBool raw = PR_FALSE;
PLOptState *optstate;
PLOptStatus status;
int retval = -1;

progName = strrchr(argv[0], '/');
progName = progName ? progName + 1 : argv[0];
Expand All @@ -55,7 +56,7 @@ main(int argc, char **argv)
if (!inFile) {
fprintf(stderr, "%s: unable to open \"%s\" for reading\n",
progName, optstate->value);
return -1;
goto cleanup;
}
break;

Expand All @@ -64,7 +65,7 @@ main(int argc, char **argv)
if (!outFile) {
fprintf(stderr, "%s: unable to open \"%s\" for writing\n",
progName, optstate->value);
return -1;
goto cleanup;
}
break;

Expand All @@ -85,17 +86,19 @@ main(int argc, char **argv)
if (!outFile)
outFile = stdout;

rv = NSS_NoDB_Init(NULL); /* XXX */
rv = NSS_NoDB_Init(NULL);
if (rv != SECSuccess) {
SECU_PrintPRandOSError(progName);
return -1;
goto cleanup;
}

rv = SECU_ReadDERFromFile(&der, inFile, PR_FALSE, PR_FALSE);
if (rv == SECSuccess) {
rv = DER_PrettyPrint(outFile, &der, raw);
if (rv == SECSuccess)
return 0;
if (rv == SECSuccess) {
retval = 0;
goto cleanup;
}
}

xp_error = PORT_GetError();
Expand All @@ -105,5 +108,21 @@ main(int argc, char **argv)
if (errno) {
SECU_PrintSystemError(progName, "errno=%d", errno);
}
return 1;
retval = 1;

cleanup:
retval |= NSS_Shutdown();
if (inFile) {
PR_Close(inFile);
}
if (outFile) {
fflush(outFile);
fclose(outFile);
}
PL_DestroyOptState(optstate);
if (der.data) {
PORT_Free(der.data);
}

return retval;
}

0 comments on commit 52d3036

Please sign in to comment.