Skip to content

Commit 7ed21e6

Browse files
authored
random: Do not hardcode the target type when invoking the CSPRNG (#13308)
Instead derive the number of bytes to retrieve from the variable that is being filled.
1 parent eb23857 commit 7ed21e6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

ext/random/engine_mt19937.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *sta
240240
{
241241
zend_long seed = 0;
242242

243-
if (php_random_bytes_silent(&seed, sizeof(zend_long)) == FAILURE) {
243+
if (php_random_bytes_silent(&seed, sizeof(seed)) == FAILURE) {
244244
seed = GENERATE_SEED();
245245
}
246246

@@ -277,7 +277,7 @@ PHP_METHOD(Random_Engine_Mt19937, __construct)
277277

278278
if (seed_is_null) {
279279
/* MT19937 has a very large state, uses CSPRNG for seeding only */
280-
if (php_random_bytes_throw(&seed, sizeof(zend_long)) == FAILURE) {
280+
if (php_random_bytes_throw(&seed, sizeof(seed)) == FAILURE) {
281281
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
282282
RETURN_THROWS();
283283
}

ext/random/engine_secure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static php_random_result generate(php_random_status *status)
2929
{
3030
zend_ulong r = 0;
3131

32-
php_random_bytes_throw(&r, sizeof(zend_ulong));
32+
php_random_bytes_throw(&r, sizeof(r));
3333

3434
return (php_random_result){
3535
.size = sizeof(zend_ulong),

0 commit comments

Comments
 (0)