Commit 1c6aab6a authored by Richard Levitte's avatar Richard Levitte
Browse files

Make 'openssl prime ""' not segfault



Fixes RT#4699

Reviewed-by: default avatarTim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1668)
parent 99c002b3
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -128,16 +128,24 @@ int MAIN(int argc, char **argv)
        BIO_printf(bio_out, "%s\n", s);
        OPENSSL_free(s);
    } else {
        int r;

        if (hex)
            BN_hex2bn(&bn, argv[0]);
            r = BN_hex2bn(&bn, argv[0]);
        else
            BN_dec2bn(&bn, argv[0]);
            r = BN_dec2bn(&bn, argv[0]);

        if(!r) {
            BIO_printf(bio_err, "Failed to process value (%s)\n", argv[0]);
            goto end;
        }

        BN_print(bio_out, bn);
        BIO_printf(bio_out, " is %sprime\n",
                   BN_is_prime_ex(bn, checks, NULL, NULL) ? "" : "not ");
    }

 end:
    BN_free(bn);
    BIO_free_all(bio_out);