File tree 3 files changed +47
-0
lines changed
3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ PHP NEWS
24
24
. Fixed bug GH-9083 (undefined behavior during shifting). (timwolla)
25
25
. Fixed bug GH-9088, GH-9056 (incorrect expansion of bytes when
26
26
generating uniform integers within a given range). (timwolla)
27
+ . Fixed bug GH-9089 (Fix memory leak on Randomizer::__construct()
28
+ call twice) (zeriyoshi)
27
29
28
30
21 Jul 2022, PHP 8.2.0beta1
29
31
Original file line number Diff line number Diff line change @@ -70,6 +70,11 @@ PHP_METHOD(Random_Randomizer, __construct)
70
70
Z_PARAM_OBJ_OF_CLASS_OR_NULL (engine_object , random_ce_Random_Engine );
71
71
ZEND_PARSE_PARAMETERS_END ();
72
72
73
+ if (randomizer -> algo ) {
74
+ zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot call constructor twice" );
75
+ RETURN_THROWS ();
76
+ }
77
+
73
78
/* Create default RNG instance */
74
79
if (!engine_object ) {
75
80
engine_object = random_ce_Random_Engine_Secure -> create_object (random_ce_Random_Engine_Secure );
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Random: Randomizer: Disallow manually calling __construct
3
+ --FILE--
4
+ <?php
5
+
6
+ final class UserEngine implements \Random \Engine
7
+ {
8
+ public function generate (): string
9
+ {
10
+ return \random_byte (4 ); /* 32-bit */
11
+ }
12
+ }
13
+
14
+ try {
15
+ (new \Random \Randomizer ())->__construct ();
16
+ } catch (\BadMethodCallException $ e ) {
17
+ echo $ e ->getMessage () . PHP_EOL ;
18
+ }
19
+
20
+ try {
21
+ $ r = new \Random \Randomizer (new \Random \Engine \Xoshiro256StarStar ());
22
+ $ r ->__construct (new \Random \Engine \PcgOneseq128XslRr64 ());
23
+ } catch (\BadMethodCallException $ e ) {
24
+ echo $ e ->getMessage () . PHP_EOL ;
25
+ }
26
+
27
+ try {
28
+ $ r = new \Random \Randomizer (new \UserEngine ());
29
+ $ r ->__construct (new \UserEngine ());
30
+ } catch (\BadMethodCallException $ e ) {
31
+ echo $ e ->getMessage () . PHP_EOL ;
32
+ }
33
+
34
+ die ('success ' );
35
+ ?>
36
+ --EXPECT--
37
+ Cannot call constructor twice
38
+ Cannot call constructor twice
39
+ Cannot call constructor twice
40
+ success
You can’t perform that action at this time.
0 commit comments