From 88d61717dea2609ba0f358c87c0d540cfc3ec10a Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 13 May 2020 14:25:56 +0200 Subject: [PATCH] fix #1: Segfault on PHP 7.4 with empty array closes #2 --- php_json_post.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/php_json_post.c b/php_json_post.c index d9b7295..c2e5ba6 100644 --- a/php_json_post.c +++ b/php_json_post.c @@ -68,8 +68,13 @@ static SAPI_POST_HANDLER_FUNC(php_json_post_handler) switch (Z_TYPE(tmp)) { case IS_OBJECT: case IS_ARRAY: - zval_dtor(arg); - ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &tmp); + if (zend_hash_num_elements(HASH_OF(&tmp))) { + zval_dtor(arg); + ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &tmp); + } else { + /* PHP-7.4 optimizes empty array */ + zval_ptr_dtor(&tmp); + } break; default: break; -- 2.30.2