Skip to content

Commit 5aca25a

Browse files
authored
[ci skip] Improve error message of an engine fails to seed from the CSPRNG (#9160)
1 parent 056e968 commit 5aca25a

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

ext/random/engine_mt19937.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ PHP_METHOD(Random_Engine_Mt19937, __construct)
279279

280280
if (seed_is_null) {
281281
/* MT19937 has a very large state, uses CSPRNG for seeding only */
282-
if (php_random_bytes_silent(&seed, sizeof(zend_long)) == FAILURE) {
283-
zend_throw_exception(spl_ce_RuntimeException, "Random number generation failed", 0);
282+
if (php_random_bytes_throw(&seed, sizeof(zend_long)) == FAILURE) {
283+
zend_throw_exception(spl_ce_RuntimeException, "Failed to generate a random seed", 0);
284284
RETURN_THROWS();
285285
}
286286
}

ext/random/engine_pcgoneseq128xslrr64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct)
148148
ZEND_PARSE_PARAMETERS_END();
149149

150150
if (seed_is_null) {
151-
if (php_random_bytes_silent(&state->state, sizeof(php_random_uint128_t)) == FAILURE) {
152-
zend_throw_exception(spl_ce_RuntimeException, "Random number generation failed", 0);
151+
if (php_random_bytes_throw(&state->state, sizeof(php_random_uint128_t)) == FAILURE) {
152+
zend_throw_exception(spl_ce_RuntimeException, "Failed to generate a random seed", 0);
153153
RETURN_THROWS();
154154
}
155155
} else {

ext/random/engine_xoshiro256starstar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct)
206206
ZEND_PARSE_PARAMETERS_END();
207207

208208
if (seed_is_null) {
209-
if (php_random_bytes_silent(&state->state, 32) == FAILURE) {
210-
zend_throw_exception(spl_ce_RuntimeException, "Random number generation failed", 0);
209+
if (php_random_bytes_throw(&state->state, 32) == FAILURE) {
210+
zend_throw_exception(spl_ce_RuntimeException, "Failed to generate a random seed", 0);
211211
RETURN_THROWS();
212212
}
213213
} else {

0 commit comments

Comments
 (0)