Skip to content

Commit f34721c

Browse files
authored
random: Initialize the mode field when seeding in php_random_default_status() (#13690)
This is not just an issue due to missing initialization since moving the state struct directly into the module globals. In earlier versions changing the mode to `MT_RAND_PHP` within a single request would also affect the mode for subsequent requests. Original commit message follows: This is a follow-up fix for GH-13579. The issue was detected in the nightly MSAN build. (cherry picked from commit bf0abd1)
1 parent 6985aff commit f34721c

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ PHP NEWS
2626
- Random:
2727
. Fixed bug GH-13544 (Pre-PHP 8.2 compatibility for mt_srand with unknown
2828
modes). (timwolla)
29+
. Fixed bug GH-13690 (Global Mt19937 is not properly reset in-between
30+
requests when MT_RAND_PHP is used). (timwolla)
2931

3032
- Session:
3133
. Fixed bug GH-13680 (Segfault with session_decode and compilation error).

ext/random/random.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ PHPAPI php_random_status *php_random_default_status(void)
334334
php_random_status *status = RANDOM_G(mt19937);
335335

336336
if (!RANDOM_G(mt19937_seeded)) {
337+
((php_random_status_state_mt19937 *)status->state)->mode = MT_RAND_MT19937;
337338
php_random_mt19937_seed_default(status->state);
338339
RANDOM_G(mt19937_seeded) = true;
339340
}

0 commit comments

Comments
 (0)