]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
rand: fix memory overrun bug
authorPauli <ppzgs1@gmail.com>
Wed, 4 Jun 2025 23:50:34 +0000 (09:50 +1000)
committerTomas Mraz <tomas@openssl.org>
Mon, 9 Jun 2025 08:26:47 +0000 (10:26 +0200)
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27766)

(cherry picked from commit da585e214cf98468e28f4c12ec96ecc7a6192746)

providers/implementations/rands/test_rng.c

index 57b36469caa58e560f3e68f4cdc744f4bc7c3417..85cea02d2671c383ace8ac89d19b3f419586428f 100644 (file)
@@ -157,7 +157,7 @@ static int test_rng_reseed(ossl_unused void *vtest,
 
 static size_t test_rng_nonce(void *vtest, unsigned char *out,
                              unsigned int strength, size_t min_noncelen,
-                             ossl_unused size_t max_noncelen)
+                             size_t max_noncelen)
 {
     PROV_TEST_RNG *t = (PROV_TEST_RNG *)vtest;
     size_t i;
@@ -173,9 +173,10 @@ static size_t test_rng_nonce(void *vtest, unsigned char *out,
 
     if (t->nonce == NULL)
         return 0;
+    i = t->nonce_len > max_noncelen ? max_noncelen : t->nonce_len;
     if (out != NULL)
-        memcpy(out, t->nonce, t->nonce_len);
-    return t->nonce_len;
+        memcpy(out, t->nonce, i);
+    return i;
 }
 
 static int test_rng_get_ctx_params(void *vtest, OSSL_PARAM params[])