From 3c6fb57a5bec06a248166bcf10b03e0acf4eeebc Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 17 Sep 2024 01:16:54 +0200 Subject: [PATCH] Fix GH-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. --- main/php_variables.c | 1 + tests/basic/gh15905.phpt | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/basic/gh15905.phpt diff --git a/main/php_variables.c b/main/php_variables.c index eb442c3d2f99f..bac5b1b673b61 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -897,6 +897,7 @@ static bool php_auto_globals_create_server(zend_string *name) } else { zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_SERVER]); array_init(&PG(http_globals)[TRACK_VARS_SERVER]); + zend_hash_real_init_mixed(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])); } check_http_proxy(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])); diff --git a/tests/basic/gh15905.phpt b/tests/basic/gh15905.phpt new file mode 100644 index 0000000000000..6636b97024276 --- /dev/null +++ b/tests/basic/gh15905.phpt @@ -0,0 +1,12 @@ +--TEST-- +GH-15905 (Assertion failure for TRACK_VARS_SERVER) +--INI-- +variables_order=E +auto_globals_jit=0 +register_argc_argv=1 +--FILE-- + +--EXPECT-- +okay