Add a couple of checks to prime app.
authorDr. Stephen Henson <steve@openssl.org>
Tue, 10 May 2016 19:49:50 +0000 (20:49 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Tue, 10 May 2016 21:53:39 +0000 (22:53 +0100)
RT#4402

Reviewed-by: Richard Levitte <levitte@openssl.org>
apps/prime.c

index 3cbf98d4e68209fd64d774fb01547b3d2b33e072..072421e314193c360bd15155851c2c427ccdd591 100644 (file)
@@ -122,11 +122,19 @@ int prime_main(int argc, char **argv)
             goto end;
         }
         bn = BN_new();
+        if (bn == NULL) {
+            BIO_printf(bio_err, "Out of memory.\n");
+            goto end;
+        }
         if (!BN_generate_prime_ex(bn, bits, safe, NULL, NULL, NULL)) {
             BIO_printf(bio_err, "Failed to generate prime.\n");
             goto end;
         }
         s = hex ? BN_bn2hex(bn) : BN_bn2dec(bn);
+        if (s == NULL) {
+            BIO_printf(bio_err, "Out of memory.\n");
+            goto end;
+        }
         BIO_printf(bio_out, "%s\n", s);
         OPENSSL_free(s);
     } else {