diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-07-07 09:08:56 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-07-07 09:15:43 +0200 |
commit | dadb92ea35688a82bec7d4dca5a6edd446c50576 (patch) | |
tree | 75d5ca7a9ee1acc082eba01a75c867022d95aa48 /ext/standard/array.c | |
parent | df8119d3e1228ea0dcc14f18027e2d57de76d28e (diff) | |
download | php-git-dadb92ea35688a82bec7d4dca5a6edd446c50576.tar.gz |
Don't allow separation in array functions
The only case here that might be *somewhat* sensible is the userdata
argument of array_walk(), which could be used to keep persistent state
between callback invokations -- with the WTF moment that the final
result after the walk finishes will be unchanged. Nowdays, this is
much better achieved using a closure with a use-by-reference.
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r-- | ext/standard/array.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index 530e72c4af..3eb06bd3c4 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -921,7 +921,7 @@ static inline int php_array_user_compare_unstable(Bucket *f, Bucket *s) /* {{{ * BG(user_compare_fci).param_count = 2; BG(user_compare_fci).params = args; BG(user_compare_fci).retval = &retval; - BG(user_compare_fci).no_separation = 0; + BG(user_compare_fci).no_separation = 1; call_failed = zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache)) == FAILURE || Z_TYPE(retval) == IS_UNDEF; zval_ptr_dtor(&args[1]); zval_ptr_dtor(&args[0]); @@ -1063,7 +1063,7 @@ static inline int php_array_user_key_compare_unstable(Bucket *f, Bucket *s) /* { BG(user_compare_fci).param_count = 2; BG(user_compare_fci).params = args; BG(user_compare_fci).retval = &retval; - BG(user_compare_fci).no_separation = 0; + BG(user_compare_fci).no_separation = 1; call_failed = zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache)) == FAILURE || Z_TYPE(retval) == IS_UNDEF; zval_ptr_dtor(&args[1]); zval_ptr_dtor(&args[0]); @@ -1374,7 +1374,7 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */ BG(array_walk_fci).retval = &retval; BG(array_walk_fci).param_count = userdata ? 3 : 2; BG(array_walk_fci).params = args; - BG(array_walk_fci).no_separation = 0; + BG(array_walk_fci).no_separation = 1; zend_hash_internal_pointer_reset_ex(target_hash, &pos); ht_iter = zend_hash_iterator_add(target_hash, pos); @@ -4546,7 +4546,7 @@ static int zval_user_compare(zval *a, zval *b) /* {{{ */ BG(user_compare_fci).param_count = 2; BG(user_compare_fci).params = args; BG(user_compare_fci).retval = &retval; - BG(user_compare_fci).no_separation = 0; + BG(user_compare_fci).no_separation = 1; if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache)) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { zend_long ret = zval_get_long(&retval); @@ -5906,7 +5906,7 @@ PHP_FUNCTION(array_reduce) fci.retval = &retval; fci.param_count = 2; - fci.no_separation = 0; + fci.no_separation = 1; ZEND_HASH_FOREACH_VAL(htbl, operand) { ZVAL_COPY_VALUE(&args[0], return_value); @@ -5959,7 +5959,7 @@ PHP_FUNCTION(array_filter) if (ZEND_FCI_INITIALIZED(fci)) { have_callback = 1; - fci.no_separation = 0; + fci.no_separation = 1; fci.retval = &retval; if (use_type == ARRAY_FILTER_USE_BOTH) { fci.param_count = 2; @@ -6062,7 +6062,7 @@ PHP_FUNCTION(array_map) fci.retval = &result; fci.param_count = 1; fci.params = &arg; - fci.no_separation = 0; + fci.no_separation = 1; ZVAL_COPY(&arg, zv); ret = zend_call_function(&fci, &fci_cache); @@ -6151,7 +6151,7 @@ PHP_FUNCTION(array_map) fci.retval = &result; fci.param_count = n_arrays; fci.params = params; - fci.no_separation = 0; + fci.no_separation = 1; if (zend_call_function(&fci, &fci_cache) != SUCCESS || Z_TYPE(result) == IS_UNDEF) { efree(array_pos); |