From c2f7614fb7b93fe3792068077ff01384f42f39bc Mon Sep 17 00:00:00 2001 From: Peiwei Hu Date: Sat, 28 May 2022 23:46:33 +0800 Subject: Fix the checks of RAND_bytes Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale Reviewed-by: Todd Short (Merged from https://github.com/openssl/openssl/pull/18424) --- test/bad_dtls_test.c | 2 +- test/drbgtest.c | 2 +- test/ecdsatest.c | 2 +- test/exptest.c | 6 +++--- test/wpackettest.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/bad_dtls_test.c b/test/bad_dtls_test.c index 8849269173..2e12de2702 100644 --- a/test/bad_dtls_test.c +++ b/test/bad_dtls_test.c @@ -331,7 +331,7 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr, } while (len % 16); /* Generate IV, and encrypt */ - if (!TEST_true(RAND_bytes(iv, sizeof(iv))) + if (!TEST_int_gt(RAND_bytes(iv, sizeof(iv)), 0) || !TEST_ptr(enc_ctx = EVP_CIPHER_CTX_new()) || !TEST_true(EVP_CipherInit_ex(enc_ctx, EVP_aes_128_cbc(), NULL, enc_key, iv, 1)) diff --git a/test/drbgtest.c b/test/drbgtest.c index a6fd46595a..8af64d23b0 100644 --- a/test/drbgtest.c +++ b/test/drbgtest.c @@ -531,7 +531,7 @@ static int test_rand_fork_safety(int i) success = 0; /* request a single byte from each of the DRBGs before the next run */ - if (!TEST_true(RAND_bytes(random, 1) && RAND_priv_bytes(random, 1))) + if (!TEST_int_gt(RAND_bytes(random, 1), 0) || !TEST_int_gt(RAND_priv_bytes(random, 1), 0)) success = 0; return success; diff --git a/test/ecdsatest.c b/test/ecdsatest.c index 282b9660d3..0baeb89230 100644 --- a/test/ecdsatest.c +++ b/test/ecdsatest.c @@ -223,7 +223,7 @@ static int test_builtin(int n, int as) if (!TEST_ptr(mctx = EVP_MD_CTX_new()) /* get some random message data */ - || !TEST_true(RAND_bytes(tbs, sizeof(tbs))) + || !TEST_int_gt(RAND_bytes(tbs, sizeof(tbs)), 0) /* real key */ || !TEST_ptr(eckey = EC_KEY_new_by_curve_name(nid)) || !TEST_true(EC_KEY_generate_key(eckey)) diff --git a/test/exptest.c b/test/exptest.c index 675984c8cb..7c91e64a58 100644 --- a/test/exptest.c +++ b/test/exptest.c @@ -144,21 +144,21 @@ static int test_mod_exp(int round) || !TEST_ptr(m = BN_new())) goto err; - if (!TEST_true(RAND_bytes(&c, 1))) + if (!TEST_int_gt(RAND_bytes(&c, 1), 0)) goto err; c = (c % BN_BITS) - BN_BITS2; if (!TEST_true(BN_rand(a, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))) goto err; - if (!TEST_true(RAND_bytes(&c, 1))) + if (!TEST_int_gt(RAND_bytes(&c, 1), 0)) goto err; c = (c % BN_BITS) - BN_BITS2; if (!TEST_true(BN_rand(b, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))) goto err; - if (!TEST_true(RAND_bytes(&c, 1))) + if (!TEST_int_gt(RAND_bytes(&c, 1), 0)) goto err; c = (c % BN_BITS) - BN_BITS2; if (!TEST_true(BN_rand(m, NUM_BITS + c, BN_RAND_TOP_ONE, diff --git a/test/wpackettest.c b/test/wpackettest.c index a90c9a1553..0aea34188b 100644 --- a/test/wpackettest.c +++ b/test/wpackettest.c @@ -410,7 +410,7 @@ static int test_WPACKET_init_der(void) return cleanup(&pkt); /* Generate random packet data for test */ - if (!TEST_true(RAND_bytes(&testdata2[3], sizeof(testdata2) - 3))) + if (!TEST_int_gt(RAND_bytes(&testdata2[3], sizeof(testdata2) - 3), 0)) return 0; /* @@ -581,7 +581,7 @@ static int test_WPACKET_quic_vlint_random(void) PACKET read_pkt = {0}; for (i = 0; i < 10000; ++i) { - if (!TEST_true(RAND_bytes(rand_data, sizeof(rand_data)))) + if (!TEST_int_gt(RAND_bytes(rand_data, sizeof(rand_data)), 0)) return cleanup(&pkt); expected = *(uint64_t*)rand_data; -- cgit v1.2.1