Skip to content

Commit c10fb01

Browse files
cmb69jorgsowa
authored andcommitted
Fix phpGH-15905: Assertion failure for TRACK_VARS_SERVER
When the superglobals are eagerly initialized, but "S" is not contained in `variables_order`, `TRACK_VARS_SERVER` is created as empty array with refcount > 1. Since this hash table may later be modified, a flag is set which allows such COW violations for assertions. However, when `register_argc_argv` is on, the so far uninitialized hash table is updated with `argv`, what causes the hash table to be initialized, what drops the allow-COW-violations flag. The following update with `argc` then triggers a refcount violation assertion. Since we consider `HT_ALLOW_COW_VIOLATION` a hack, we do not want to keep the flag during hash table initialization, so we initialize the hash table right away after creation for this code path. Closes phpGH-15930.
1 parent 3b784a8 commit c10fb01

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

main/php_variables.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ static bool php_auto_globals_create_server(zend_string *name)
893893
} else {
894894
zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_SERVER]);
895895
array_init(&PG(http_globals)[TRACK_VARS_SERVER]);
896+
zend_hash_real_init_mixed(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]));
896897
}
897898

898899
check_http_proxy(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]));

tests/basic/gh15905.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-15905 (Assertion failure for TRACK_VARS_SERVER)
3+
--INI--
4+
variables_order=E
5+
auto_globals_jit=0
6+
register_argc_argv=1
7+
--FILE--
8+
<?php
9+
echo "okay\n";
10+
?>
11+
--EXPECT--
12+
okay

0 commit comments

Comments
 (0)