Skip to content

Commit

Permalink
Fix GH-15905: Assertion failure for TRACK_VARS_SERVER
Browse files Browse the repository at this point in the history
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 GH-15930.
  • Loading branch information
cmb69 committed Sep 26, 2024
1 parent 24d5912 commit 87d59d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PHP NEWS
- Core:
. Fixed bug GH-15712: zend_strtod overflow with precision INI set on
large value. (David Carlier)
. Fixed bug GH-15905 (Assertion failure for TRACK_VARS_SERVER). (cmb)

- Date:
. Fixed bug GH-15582: Crash when not calling parent constructor of
Expand Down
1 change: 1 addition & 0 deletions main/php_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
12 changes: 12 additions & 0 deletions tests/basic/gh15905.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php
echo "okay\n";
?>
--EXPECT--
okay

0 comments on commit 87d59d7

Please sign in to comment.