]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix the checks of RAND_bytes
authorPeiwei Hu <jlu.hpw@foxmail.com>
Sat, 28 May 2022 15:46:33 +0000 (23:46 +0800)
committerTodd Short <todd.short@me.com>
Thu, 2 Jun 2022 14:36:56 +0000 (10:36 -0400)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18424)

test/bad_dtls_test.c
test/drbgtest.c
test/ecdsatest.c
test/exptest.c
test/wpackettest.c

index 8849269173f154579d6262e11c86e2c8d25de9b0..2e12de2702b0ba2220a3a92aeb98ddc2f3f1e2fc 100644 (file)
@@ -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))
index a6fd46595aa95f390c07c8af15d9b161cb4e4ec6..8af64d23b0cae6539f4063c2b9e32194576a85a8 100644 (file)
@@ -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;
index 282b9660d315ff5da965b33347e07b503e0504fe..0baeb8923046793766f5ee6ddd15b6ceef968e92 100644 (file)
@@ -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))
index 675984c8cbb47c9f490d52794359384977bb461b..7c91e64a584908428b38ab4c8b17b20527343d35 100644 (file)
@@ -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,
index a90c9a155389290a002eee5be54775c9539c11ef..0aea34188b65525dda0f0a5bc789d2028e8f2b21 100644 (file)
@@ -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;