From af77d3b8dac99dc814a714c66d7d359562a399c4 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 21 Jul 2023 13:25:50 +0200 Subject: [PATCH] Fix GH-11716: cli server crashes on SIGINT when compiled with ZEND_RC_DEBUG=1 Closes GH-11757. --- NEWS | 4 ++++ Zend/zend_hash.c | 5 +++++ sapi/cli/php_cli_server.c | 3 +++ 3 files changed, 12 insertions(+) diff --git a/NEWS b/NEWS index ccf953141cba2..a5b6a7901b629 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.1.23 +- CLI: + . Fixed bug GH-11716 (cli server crashes on SIGINT when compiled with + ZEND_RC_DEBUG=1). (nielsdos) + - FFI: . Fix leaking definitions when using FFI::cdef()->new(...). (ilutov) diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 5032668e1bfab..b96a951101171 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -878,6 +878,11 @@ static zend_always_inline zval *_zend_hash_str_add_or_update_i(HashTable *ht, co ht->nNumOfElements++; p = ht->arData + idx; p->key = key = zend_string_init(str, len, GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); +#if ZEND_RC_DEBUG + if (GC_FLAGS(ht) & GC_PERSISTENT_LOCAL) { + GC_MAKE_PERSISTENT_LOCAL(key); + } +#endif p->h = ZSTR_H(key) = h; HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS; if (flag & HASH_LOOKUP) { diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 626c58fcc2457..f13edc568a652 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -1340,7 +1340,9 @@ static int php_cli_server_request_ctor(php_cli_server_request *req) /* {{{ */ req->query_string = NULL; req->query_string_len = 0; zend_hash_init(&req->headers, 0, NULL, char_ptr_dtor_p, 1); + GC_MAKE_PERSISTENT_LOCAL(&req->headers); zend_hash_init(&req->headers_original_case, 0, NULL, NULL, 1); + GC_MAKE_PERSISTENT_LOCAL(&req->headers_original_case); req->content = NULL; req->content_len = 0; req->ext = NULL; @@ -2248,6 +2250,7 @@ static int php_cli_server_mime_type_ctor(php_cli_server *server, const php_cli_s const php_cli_server_ext_mime_type_pair *pair; zend_hash_init(&server->extension_mime_types, 0, NULL, NULL, 1); + GC_MAKE_PERSISTENT_LOCAL(&server->extension_mime_types); for (pair = mime_type_map; pair->ext; pair++) { size_t ext_len = strlen(pair->ext);