[php-src] PHP-8.2: random: Initialize the `mode` field when seeding in `php_random_default_status()` (#13690)
| From: | Tim Düsterhus via GitHub | Date: | Wed, 13 Mar 2024 19:27:36 +0000 |
| Subject: | [php-src] PHP-8.2: random: Initialize the `mode` field when seeding in `php_random_default_status()` (#13690) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127719@lists.php.net to get a copy of this message | ||
Author: Tim Düsterhus (TimWolla)
Committer: GitHub (web-flow)
Pusher: TimWolla
Date: 2024-03-13T20:13:48+01:00
Commit: https://github.com/php/php-src/commit/f34721cabd3f6f12ccc0c06fbd8534b650e10fe5
Raw diff: https://github.com/php/php-src/commit/f34721cabd3f6f12ccc0c06fbd8534b650e10fe5.diff
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 bf0abd1629291c193064a9cb95a2da3565decc38)
Changed paths:
M NEWS
M ext/random/random.c
Diff:
diff --git a/NEWS b/NEWS
index 4598f8bea7502..ea7909695d14a 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,8 @@ PHP NEWS
- Random:
. Fixed bug GH-13544 (Pre-PHP 8.2 compatibility for mt_srand with unknown
modes). (timwolla)
+ . Fixed bug GH-13690 (Global Mt19937 is not properly reset in-between
+ requests when MT_RAND_PHP is used). (timwolla)
- Session:
. Fixed bug GH-13680 (Segfault with session_decode and compilation error).
diff --git a/ext/random/random.c b/ext/random/random.c
index 9f9da28962d15..e30a04259fb2b 100644
--- a/ext/random/random.c
+++ b/ext/random/random.c
@@ -334,6 +334,7 @@ PHPAPI php_random_status *php_random_default_status(void)
php_random_status *status = RANDOM_G(mt19937);
if (!RANDOM_G(mt19937_seeded)) {
+ ((php_random_status_state_mt19937 *)status->state)->mode = MT_RAND_MT19937;
php_random_mt19937_seed_default(status->state);
RANDOM_G(mt19937_seeded) = true;
}