com php-src: Don't leave holes in func_get_args() and backtraces: Zend/tests/bug70547.phpt Zend/ zend_builtin_functions.c

From: Date: Sun, 25 Jun 2017 13:27:45 +0000
Subject: com php-src: Don't leave holes in func_get_args() and backtraces: Zend/tests/bug70547.phpt Zend/ zend_builtin_functions.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-98199@lists.php.net to get a copy of this message
Commit: de66e80d757f2a89fa16ee436d89ecc428f369a9 Author: Nikita Popov <nikita.ppv@gmail.com> Sun, 25 Jun 2017 15:08:36 +0200 Parents: fda0a8b735e468f03b32bc099d8f4aa173d2b9f7 Branches: PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=de66e80d757f2a89fa16ee436d89ecc428f369a9 Log: Don't leave holes in func_get_args() and backtraces Argument lists should always be continuous and hole-free, even if local variables are unset. Replace UNDEF values with NULLs. Changed paths: M Zend/tests/bug70547.phpt M Zend/zend_builtin_functions.c Diff: diff --git a/Zend/tests/bug70547.phpt b/Zend/tests/bug70547.phpt index 1b4c35d..f793e70 100644 --- a/Zend/tests/bug70547.phpt +++ b/Zend/tests/bug70547.phpt @@ -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" } diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 3b04ead..a429ca0 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -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; } } /* }}} */

« previous php.cvs (#98199) next »