From 8317a147b9cb5ab0cd5631d46ba12e6cbdabacc7 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:59:21 +0200 Subject: [PATCH] Use php_random_bytes_silent() where possible in gmp_init_random() (#10944) See GH-10942. --- ext/gmp/gmp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 96536ff3bde..ff2b37ae09f 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -1729,7 +1729,11 @@ static void gmp_init_random(void) /* Initialize */ gmp_randinit_mt(GMPG(rand_state)); /* Seed */ - gmp_randseed_ui(GMPG(rand_state), GENERATE_SEED()); + zend_long seed = 0; + if (php_random_bytes_silent(&seed, sizeof(zend_long)) == FAILURE) { + seed = GENERATE_SEED(); + } + gmp_randseed_ui(GMPG(rand_state), seed); GMPG(rand_initialized) = 1; }