summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorTim Taubert <ttaubert@mozilla.com>2016-07-06 14:14:55 +0200
committerTim Taubert <ttaubert@mozilla.com>2016-07-06 14:14:55 +0200
commit8a90fef3d7fb293e2b83c6e21131cfb1bb8203dd (patch)
treef4922184c5efd9edc76eac8427bfc80f9bd186f4 /cmd
parenta19dbbd6b407e9a41c0a53bd05d040c8c28e444a (diff)
downloadnss-hg-8a90fef3d7fb293e2b83c6e21131cfb1bb8203dd.tar.gz
Bug 1284828 - Enable S/MIME tests on LSan runs r=franziskus
Diffstat (limited to 'cmd')
-rw-r--r--cmd/p7content/p7content.c28
-rw-r--r--cmd/p7env/p7env.c24
-rw-r--r--cmd/p7sign/p7sign.c2
-rw-r--r--cmd/p7verify/p7verify.c8
-rw-r--r--cmd/smimetools/cmsutil.c18
5 files changed, 66 insertions, 14 deletions
diff --git a/cmd/p7content/p7content.c b/cmd/p7content/p7content.c
index a396c70bf..d8c4d6524 100644
--- a/cmd/p7content/p7content.c
+++ b/cmd/p7content/p7content.c
@@ -155,6 +155,7 @@ DecodeAndPrintFile(FILE *out, PRFileDesc *in, char *progName)
fprintf(out, "There were%s certs or crls included.\n",
SEC_PKCS7ContainsCertsOrCrls(cinfo) ? "" : " no");
+ SECITEM_FreeItem(&derdata, PR_FALSE);
SEC_PKCS7DestroyContentInfo(cinfo);
return 0;
}
@@ -172,6 +173,7 @@ main(int argc, char **argv)
PLOptState *optstate;
PLOptStatus status;
SECStatus rv;
+ int error = 0;
progName = strrchr(argv[0], '/');
progName = progName ? progName + 1 : argv[0];
@@ -194,7 +196,8 @@ main(int argc, char **argv)
if (!inFile) {
fprintf(stderr, "%s: unable to open \"%s\" for reading\n",
progName, optstate->value);
- return -1;
+ error = -1;
+ goto done;
}
break;
@@ -203,7 +206,8 @@ main(int argc, char **argv)
if (!outFile) {
fprintf(stderr, "%s: unable to open \"%s\" for writing\n",
progName, optstate->value);
- return -1;
+ error = -1;
+ goto done;
}
break;
@@ -222,6 +226,8 @@ main(int argc, char **argv)
break;
}
}
+ PL_DestroyOptState(optstate);
+
if (status == PL_OPT_BAD)
Usage(progName);
@@ -235,19 +241,29 @@ main(int argc, char **argv)
rv = NSS_Init(SECU_ConfigDirectory(NULL));
if (rv != SECSuccess) {
SECU_PrintPRandOSError(progName);
- return -1;
+ error = -1;
+ goto done;
}
PK11_SetPasswordFunc(SECU_GetModulePassword);
if (DecodeAndPrintFile(outFile, inFile, progName)) {
SECU_PrintError(progName, "problem decoding data");
- return -1;
+ error = -1;
+ goto done;
+ }
+
+done:
+ if (inFile && inFile != PR_STDIN) {
+ PR_Close(inFile);
+ }
+ if (outFile && outFile != stdout) {
+ fclose(outFile);
}
if (NSS_Shutdown() != SECSuccess) {
- exit(1);
+ error = -1;
}
- return 0;
+ return error;
}
diff --git a/cmd/p7env/p7env.c b/cmd/p7env/p7env.c
index b798101ef..1cf17540b 100644
--- a/cmd/p7env/p7env.c
+++ b/cmd/p7env/p7env.c
@@ -190,12 +190,13 @@ main(int argc, char **argv)
progName);
return -1;
}
- rcpt->nickname = strdup(optstate->value);
+ rcpt->nickname = PORT_Strdup(optstate->value);
rcpt->cert = NULL;
rcpt->next = NULL;
break;
}
}
+ PL_DestroyOptState(optstate);
if (!recipients)
Usage(progName);
@@ -235,5 +236,26 @@ main(int argc, char **argv)
return -1;
}
+ /* free certs */
+ for (rcpt = recipients; rcpt != NULL; ) {
+ struct recipient *next = rcpt->next;
+ CERT_DestroyCertificate(rcpt->cert);
+ PORT_Free(rcpt->nickname);
+ PORT_Free(rcpt);
+ rcpt = next;
+ }
+
+ if (inFile && inFile != stdin) {
+ fclose(inFile);
+ }
+ if (outFile && outFile != stdout) {
+ fclose(outFile);
+ }
+
+ if (NSS_Shutdown() != SECSuccess) {
+ SECU_PrintError(progName, "NSS shutdown:");
+ return -1;
+ }
+
return 0;
}
diff --git a/cmd/p7sign/p7sign.c b/cmd/p7sign/p7sign.c
index 605eee415..3ac462006 100644
--- a/cmd/p7sign/p7sign.c
+++ b/cmd/p7sign/p7sign.c
@@ -132,6 +132,7 @@ SignFile(FILE *outFile, PRFileDesc *inFile, CERTCertificate *cert,
rv = SEC_PKCS7Encode(cinfo, SignOut, outFile, NULL,
NULL, &pwdata);
+ SECITEM_FreeItem(&data2sign, PR_FALSE);
SEC_PKCS7DestroyContentInfo(cinfo);
if (rv != SECSuccess)
@@ -212,6 +213,7 @@ main(int argc, char **argv)
break;
}
}
+ PL_DestroyOptState(optstate);
if (!keyName)
Usage(progName);
diff --git a/cmd/p7verify/p7verify.c b/cmd/p7verify/p7verify.c
index bb92f990f..ba38e1158 100644
--- a/cmd/p7verify/p7verify.c
+++ b/cmd/p7verify/p7verify.c
@@ -171,6 +171,7 @@ HashDecodeAndVerify(FILE *out, FILE *content, PRFileDesc *signature,
fprintf(out, "invalid (Reason: %s).\n",
SECU_Strerror(PORT_GetError()));
+ SECITEM_FreeItem(&derdata, PR_FALSE);
SEC_PKCS7DestroyContentInfo(cinfo);
return 0;
}
@@ -245,6 +246,7 @@ main(int argc, char **argv)
}
}
}
+ PL_DestroyOptState(optstate);
if (!contentFile)
Usage(progName);
@@ -267,6 +269,12 @@ main(int argc, char **argv)
return -1;
}
+ fclose(contentFile);
+ PR_Close(signatureFile);
+ if (outFile && outFile != stdout) {
+ fclose(outFile);
+ }
+
if (NSS_Shutdown() != SECSuccess) {
exit(1);
}
diff --git a/cmd/smimetools/cmsutil.c b/cmd/smimetools/cmsutil.c
index 9a52a872d..e01fc4c7b 100644
--- a/cmd/smimetools/cmsutil.c
+++ b/cmd/smimetools/cmsutil.c
@@ -1251,7 +1251,7 @@ main(int argc, char **argv)
SECU_ConfigDirectory(optstate->value);
break;
case 'e':
- envFileName = strdup(optstate->value);
+ envFileName = PORT_Strdup(optstate->value);
encryptOptions.envFile = PR_Open(envFileName, PR_RDONLY, 00660);
break;
@@ -1379,9 +1379,6 @@ main(int argc, char **argv)
SECU_PrintError(progName, "unable to read infile");
exit(1);
}
- if (inFile != PR_STDIN) {
- PR_Close(inFile);
- }
}
if (cms_verbose) {
fprintf(stderr, "received commands\n");
@@ -1461,9 +1458,6 @@ main(int argc, char **argv)
}
} else {
exitstatus = doBatchDecode(outFile, inFile, &decodeOptions);
- if (inFile != PR_STDIN) {
- PR_Close(inFile);
- }
}
break;
case SIGN: /* -S */
@@ -1611,6 +1605,16 @@ main(int argc, char **argv)
if (outFile != stdout)
fclose(outFile);
+ if (inFile != PR_STDIN) {
+ PR_Close(inFile);
+ }
+ if (envFileName) {
+ PORT_Free(envFileName);
+ }
+ if (encryptOptions.envFile) {
+ PR_Close(encryptOptions.envFile);
+ }
+
SECITEM_FreeItem(&decodeOptions.content, PR_FALSE);
SECITEM_FreeItem(&envmsg, PR_FALSE);
SECITEM_FreeItem(&input, PR_FALSE);