Skip to content

Commit 901c528

Browse files
committed
Throw RandomException on seeding failure
1 parent ae72b46 commit 901c528

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

ext/random/engine_mt19937.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "php.h"
3131
#include "php_random.h"
3232

33-
#include "ext/spl/spl_exceptions.h"
3433
#include "Zend/zend_exceptions.h"
3534

3635
/*
@@ -280,7 +279,7 @@ PHP_METHOD(Random_Engine_Mt19937, __construct)
280279
if (seed_is_null) {
281280
/* MT19937 has a very large state, uses CSPRNG for seeding only */
282281
if (php_random_bytes_throw(&seed, sizeof(zend_long)) == FAILURE) {
283-
zend_throw_exception(spl_ce_RuntimeException, "Failed to generate a random seed", 0);
282+
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
284283
RETURN_THROWS();
285284
}
286285
}

ext/random/engine_pcgoneseq128xslrr64.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "php.h"
2424
#include "php_random.h"
2525

26-
#include "ext/spl/spl_exceptions.h"
2726
#include "Zend/zend_exceptions.h"
2827

2928
static inline void step(php_random_status_state_pcgoneseq128xslrr64 *s)
@@ -149,7 +148,7 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct)
149148

150149
if (seed_is_null) {
151150
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);
151+
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
153152
RETURN_THROWS();
154153
}
155154
} else {

ext/random/engine_xoshiro256starstar.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "php.h"
2525
#include "php_random.h"
2626

27-
#include "ext/spl/spl_exceptions.h"
2827
#include "Zend/zend_exceptions.h"
2928

3029
static inline uint64_t splitmix64(uint64_t *seed)
@@ -207,7 +206,7 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct)
207206

208207
if (seed_is_null) {
209208
if (php_random_bytes_throw(&state->state, 32) == FAILURE) {
210-
zend_throw_exception(spl_ce_RuntimeException, "Failed to generate a random seed", 0);
209+
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
211210
RETURN_THROWS();
212211
}
213212
} else {

0 commit comments

Comments
 (0)