]> granicus.if.org Git - php/commitdiff
Don't leave holes in func_get_args() and backtraces
authorNikita Popov <nikita.ppv@gmail.com>
Sun, 25 Jun 2017 13:08:36 +0000 (15:08 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 25 Jun 2017 13:27:45 +0000 (15:27 +0200)
Argument lists should always be continuous and hole-free, even if
local variables are unset. Replace UNDEF values with NULLs.

Zend/tests/bug70547.phpt
Zend/zend_builtin_functions.c

index 1b4c35d65fd135da3180ba05ff635b352ceff29d..f793e70781cdb67a5b72c577067904077d424279 100644 (file)
@@ -53,27 +53,43 @@ string(3) "1st"
 string(3) "2nd"
 NULL
 string(3) "4th"
-array(3) {
+array(4) {
   [0]=>
   string(3) "1st"
   [1]=>
   &string(3) "2nd"
+  [2]=>
+  NULL
   [3]=>
   string(3) "4th"
 }
-array(2) {
+array(4) {
+  [0]=>
+  NULL
   [1]=>
   string(3) "2nd"
+  [2]=>
+  NULL
   [3]=>
   string(3) "4th"
 }
-array(2) {
+array(4) {
+  [0]=>
+  NULL
   [1]=>
   &string(3) "2nd"
+  [2]=>
+  NULL
   [3]=>
   string(3) "4th"
 }
-array(1) {
+array(4) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
   [3]=>
   string(3) "4th"
 }
index 3b04ead955477ea310113c169fc77bfa1d12b473..a429ca013aa4fc79885852752f6ba761578f494d 100644 (file)
@@ -507,7 +507,7 @@ ZEND_FUNCTION(func_get_args)
 {
        zval *p, *q;
        uint32_t arg_count, first_extra_arg;
-       uint32_t i, n;
+       uint32_t i;
        zend_execute_data *ex = EX(prev_execute_data);
 
        if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
@@ -523,7 +523,6 @@ ZEND_FUNCTION(func_get_args)
                zend_hash_real_init(Z_ARRVAL_P(return_value), 1);
                ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
                        i = 0;
-                       n = 0;
                        p = ZEND_CALL_ARG(ex, 1);
                        if (arg_count > first_extra_arg) {
                                while (i < first_extra_arg) {
@@ -533,7 +532,8 @@ ZEND_FUNCTION(func_get_args)
                                                if (Z_OPT_REFCOUNTED_P(q)) { 
                                                        Z_ADDREF_P(q);
                                                }
-                                               n++;
+                                       } else {
+                                               q = &EG(uninitialized_zval);
                                        }
                                        ZEND_HASH_FILL_ADD(q);
                                        p++;
@@ -548,14 +548,15 @@ ZEND_FUNCTION(func_get_args)
                                        if (Z_OPT_REFCOUNTED_P(q)) { 
                                                Z_ADDREF_P(q);
                                        }
-                                       n++;
+                               } else {
+                                       q = &EG(uninitialized_zval);
                                }
                                ZEND_HASH_FILL_ADD(q);
                                p++;
                                i++;
                        }
                } ZEND_HASH_FILL_END();
-               Z_ARRVAL_P(return_value)->nNumOfElements = n;
+               Z_ARRVAL_P(return_value)->nNumOfElements = arg_count;
        }
 }
 /* }}} */
@@ -2219,7 +2220,6 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
        array_init_size(arg_array, num_args);
        if (num_args) {
                uint32_t i = 0;
-               uint32_t n = 0;
                zval *p = ZEND_CALL_ARG(call, 1);
 
                zend_hash_real_init(Z_ARRVAL_P(arg_array), 1);
@@ -2242,12 +2242,9 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
                                                        if (Z_OPT_REFCOUNTED_P(arg)) {
                                                                Z_ADDREF_P(arg);
                                                        }
-                                                       n++;
                                                        ZEND_HASH_FILL_ADD(arg);
                                                } else {
-                                                       zval tmp;
-                                                       ZVAL_UNDEF(&tmp);
-                                                       ZEND_HASH_FILL_ADD(&tmp);
+                                                       ZEND_HASH_FILL_ADD(&EG(uninitialized_zval));
                                                }
                                                i++;
                                        }
@@ -2257,9 +2254,10 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
                                                        if (Z_OPT_REFCOUNTED_P(p)) {
                                                                Z_ADDREF_P(p);
                                                        }
-                                                       n++;
+                                                       ZEND_HASH_FILL_ADD(p);
+                                               } else {
+                                                       ZEND_HASH_FILL_ADD(&EG(uninitialized_zval));
                                                }
-                                               ZEND_HASH_FILL_ADD(p);
                                                p++;
                                                i++;
                                        }
@@ -2272,14 +2270,15 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
                                        if (Z_OPT_REFCOUNTED_P(p)) {
                                                Z_ADDREF_P(p);
                                        }
-                                       n++;
+                                       ZEND_HASH_FILL_ADD(p);
+                               } else {
+                                       ZEND_HASH_FILL_ADD(&EG(uninitialized_zval));
                                }
-                               ZEND_HASH_FILL_ADD(p);
                                p++;
                                i++;
                        }
                } ZEND_HASH_FILL_END();
-               Z_ARRVAL_P(arg_array)->nNumOfElements = n;
+               Z_ARRVAL_P(arg_array)->nNumOfElements = num_args;
        }
 }
 /* }}} */