Skip to content

Commit fa51ec4

Browse files
committed
Fix GH-20656 putenv during resource shutdown
1 parent d03c80e commit fa51ec4

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎ext/standard/basic_functions.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ PHP_FUNCTION(putenv)
774774
zend_argument_value_error(1, "must have a valid syntax");
775775
RETURN_THROWS();
776776
}
777+
if (UNEXPECTED(EG(flags) & EG_FLAGS_IN_RESOURCE_SHUTDOWN)) {
778+
RETURN_FALSE;
779+
}
777780

778781
pe.putenv_string = zend_strndup(setting, setting_len);
779782
if ((p = strchr(setting, '='))) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-20656 (HashTable use-after-destroy in function table via stream wrapper magic __call() with nested redeclaration)
3+
--FILE--
4+
<?php
5+
class Loader {
6+
function stream_open() {
7+
return true;
8+
}
9+
function __call($m, $a) {
10+
$map[$obj] = putenv("LA=Gx$g_lang");
11+
function __call($m, $a) {}
12+
}
13+
}
14+
stream_wrapper_register('abc', 'Loader');
15+
require 'abc://';
16+
?>
17+
--EXPECT--

0 commit comments

Comments
 (0)