diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-01-02 21:06:40 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-01-02 21:06:40 +0100 |
commit | f4a12fc67689a830e9da1c87fd11afe5bc09deb3 (patch) | |
tree | 211ae0cd022a6c11b0026ecc7761a550c584583c /security/nss/cmd/btoa | |
parent | f7d30133221896638f7bf4f66c504255c4b14f48 (diff) | |
download | UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.gz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.lz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.xz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.zip |
Issue #1338 - Part 2: Update NSS to 3.48-RTM
Diffstat (limited to 'security/nss/cmd/btoa')
-rw-r--r-- | security/nss/cmd/btoa/btoa.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/security/nss/cmd/btoa/btoa.c b/security/nss/cmd/btoa/btoa.c index 2a5e6d4c6..f82341325 100644 --- a/security/nss/cmd/btoa/btoa.c +++ b/security/nss/cmd/btoa/btoa.c @@ -99,7 +99,6 @@ Usage(char *progName) "-w suffix"); fprintf(stderr, "%-20s (use \"c\" as a shortcut for suffix CERTIFICATE)\n", ""); - exit(-1); } int @@ -107,13 +106,13 @@ main(int argc, char **argv) { char *progName; SECStatus rv; - FILE *inFile, *outFile; - PLOptState *optstate; + FILE *inFile = NULL, *outFile = NULL; + PRBool closeIn = PR_TRUE, closeOut = PR_TRUE; + PLOptState *optstate = NULL; PLOptStatus status; char *suffix = NULL; + int exitCode = -1; - inFile = 0; - outFile = 0; progName = strrchr(argv[0], '/'); if (!progName) progName = strrchr(argv[0], '\\'); @@ -121,10 +120,12 @@ main(int argc, char **argv) /* Parse command line arguments */ optstate = PL_CreateOptState(argc, argv, "i:o:w:"); + PORT_Assert(optstate); while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) { switch (optstate->option) { default: Usage(progName); + goto loser; break; case 'i': @@ -132,7 +133,7 @@ main(int argc, char **argv) if (!inFile) { fprintf(stderr, "%s: unable to open \"%s\" for reading\n", progName, optstate->value); - return -1; + goto loser; } break; @@ -141,7 +142,7 @@ main(int argc, char **argv) if (!outFile) { fprintf(stderr, "%s: unable to open \"%s\" for writing\n", progName, optstate->value); - return -1; + goto loser; } break; @@ -166,10 +167,11 @@ main(int argc, char **argv) fprintf(stderr, "%s: Cannot change stdin to binary mode. Use -i option instead.\n", progName); - return smrv; + goto loser; } #endif inFile = stdin; + closeIn = PR_FALSE; } if (!outFile) { #if defined(WIN32) @@ -182,10 +184,11 @@ main(int argc, char **argv) fprintf(stderr, "%s: Cannot change stdout to binary mode. Use -o option instead.\n", progName); - return smrv; + goto loser; } #endif outFile = stdout; + closeOut = PR_FALSE; } if (suffix) { fprintf(outFile, "-----BEGIN %s-----\n", suffix); @@ -194,10 +197,22 @@ main(int argc, char **argv) if (rv != SECSuccess) { fprintf(stderr, "%s: lossage: error=%d errno=%d\n", progName, PORT_GetError(), errno); - return -1; + goto loser; } if (suffix) { fprintf(outFile, "-----END %s-----\n", suffix); } - return 0; + exitCode = 0; +loser: + PL_DestroyOptState(optstate); + if (inFile && closeIn) { + fclose(inFile); + } + if (outFile && closeOut) { + fclose(outFile); + } + if (suffix) { + PORT_Free(suffix); + } + return exitCode; } |