aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2004-11-27 12:55:26 +0000
committerDr. Stephen Henson <steve@openssl.org>2004-11-27 12:55:26 +0000
commit18ad97bbe710ec8a3bd89f45ea7f2edb76fdce50 (patch)
treed200a06c5300c3ac88644d05ce4a4d20b51efa35
parentee3f520276f1189d4ad091fd61413094437b661d (diff)
downloadopenssl-18ad97bbe710ec8a3bd89f45ea7f2edb76fdce50.tar.gz
Fix leaks and give an error if no argument specified in prime.c
-rw-r--r--apps/prime.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/apps/prime.c b/apps/prime.c
index 5c731a7e01..5e3333bc4a 100644
--- a/apps/prime.c
+++ b/apps/prime.c
@@ -69,18 +69,6 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
- if (bio_out == NULL)
- if ((bio_out=BIO_new(BIO_s_file())) != NULL)
- {
- BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
-#ifdef OPENSSL_SYS_VMS
- {
- BIO *tmpbio = BIO_new(BIO_f_linebuffer());
- bio_out = BIO_push(tmpbio, bio_out);
- }
-#endif
- }
-
--argc;
++argv;
while (argc >= 1 && **argv == '-')
@@ -95,16 +83,30 @@ int MAIN(int argc, char **argv)
else
{
BIO_printf(bio_err,"Unknown option '%s'\n",*argv);
- bad:
- BIO_printf(bio_err,"options are\n");
- BIO_printf(bio_err,"%-14s hex\n","-hex");
- BIO_printf(bio_err,"%-14s number of checks\n","-checks <n>");
- exit(1);
+ goto bad;
}
--argc;
++argv;
}
+ if (argv[0] == NULL)
+ {
+ BIO_printf(bio_err,"No prime specified\n");
+ goto bad;
+ }
+
+ if (bio_out == NULL)
+ if ((bio_out=BIO_new(BIO_s_file())) != NULL)
+ {
+ BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
+#ifdef OPENSSL_SYS_VMS
+ {
+ BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+ bio_out = BIO_push(tmpbio, bio_out);
+ }
+#endif
+ }
+
if(hex)
BN_hex2bn(&bn,argv[0]);
else
@@ -114,5 +116,14 @@ int MAIN(int argc, char **argv)
BIO_printf(bio_out," is %sprime\n",
BN_is_prime(bn,checks,NULL,NULL,NULL) ? "" : "not ");
+ BN_free(bn);
+ BIO_free(bio_out);
+
return 0;
+
+ bad:
+ BIO_printf(bio_err,"options are\n");
+ BIO_printf(bio_err,"%-14s hex\n","-hex");
+ BIO_printf(bio_err,"%-14s number of checks\n","-checks <n>");
+ exit(1);
}