RAND_bytes_ex: fix return check
authorPeiwei Hu <jlu.hpw@foxmail.com>
Sun, 14 Nov 2021 16:20:32 +0000 (00:20 +0800)
committerPauli <pauli@openssl.org>
Tue, 16 Nov 2021 10:01:13 +0000 (20:01 +1000)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17032)

ssl/record/tls_pad.c
test/provfetchtest.c
test/sslapitest.c
test/tls-provider.c

index 528c6055547412d4e93ea448f158ffd0a848b712..e559350461a2a6f8cf0046383ac1f43368478018 100644 (file)
@@ -251,7 +251,7 @@ static int ssl3_cbc_copy_mac(size_t *reclen,
     }
 
     /* Create the random MAC we will emit if padding is bad */
-    if (!RAND_bytes_ex(libctx, randmac, mac_size, 0))
+    if (RAND_bytes_ex(libctx, randmac, mac_size, 0) <= 0)
         return 0;
 
     if (!ossl_assert(mac != NULL && alloced != NULL))
index 1d09e6a0db4dc96e40fc15de265f3099932a2402..b1f9d08c4619d9b464c1487717a7a52e84f57056 100644 (file)
@@ -213,7 +213,7 @@ static int dummy_provider_init(const OSSL_CORE_HANDLE *handle,
      * Do some work using the child libctx, to make sure this is possible from
      * inside the init function.
      */
-    if (!RAND_bytes_ex(libctx, buf, sizeof(buf), 0))
+    if (RAND_bytes_ex(libctx, buf, sizeof(buf), 0) <= 0)
         return 0;
 
     return 1;
index 722106889b63c225a7f2fb64996cf619f7047dff..b06d5d7a14995ccb69e3106a5ff14a1f314eb172 100644 (file)
@@ -1337,7 +1337,7 @@ static int execute_test_ktls_sendfile(int tls_version, const char *cipher)
         goto end;
     }
 
-    if (!TEST_true(RAND_bytes_ex(libctx, buf, SENDFILE_SZ, 0)))
+    if (!TEST_int_gt(RAND_bytes_ex(libctx, buf, SENDFILE_SZ, 0), 0))
         goto end;
 
     out = BIO_new_file(tmpfilename, "wb");
index f8eeaeb363b4038467dcc4317d4b3b2e3fedb1d0..9ac1db51b3915a304e2a0f33cd058ac1f5cd072c 100644 (file)
@@ -813,7 +813,7 @@ unsigned int randomize_tls_group_id(OSSL_LIB_CTX *libctx)
     int i;
 
  retry:
-    if (!RAND_bytes_ex(libctx, (unsigned char *)&group_id, sizeof(group_id), 0))
+    if (RAND_bytes_ex(libctx, (unsigned char *)&group_id, sizeof(group_id), 0) <= 0)
         return 0;
     /*
      * Ensure group_id is within the IANA Reserved for private use range