fix #1: Segfault on PHP 7.4 with empty array
authorMichael Wallner <mike@php.net>
Wed, 13 May 2020 12:25:56 +0000 (14:25 +0200)
committerMichael Wallner <mike@php.net>
Wed, 13 May 2020 12:25:56 +0000 (14:25 +0200)
closes #2

php_json_post.c

index d9b72957726301f2eaf256fa75699a711570b149..c2e5ba69eabb4618b45c5c541a451472d351c959 100644 (file)
@@ -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;