Fixed bug #67874 (Crash in array_map())

This commit is contained in:
Dmitry Stogov 2014-08-20 22:06:15 +04:00
parent 9507aa99fc
commit cf09bc7825
2 changed files with 19 additions and 7 deletions

14
Zend/tests/bug67874.phpt Normal file
View File

@ -0,0 +1,14 @@
--TEST--
Bug #67874 Crash in array_map()
--FILE--
<?php
$a = array(1,2,3);
$data = array($a);
$data = array_map('current', $data);
var_dump($data);
?>
--EXPECT--
array(1) {
[0]=>
int(1)
}

View File

@ -4438,7 +4438,7 @@ PHP_FUNCTION(array_map)
if (n_arrays == 1) {
ulong num_key;
zend_string *str_key;
zval *zv;
zval *zv, arg;
if (Z_TYPE(arrays[0]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d should be an array", 2);
@ -4457,20 +4457,18 @@ PHP_FUNCTION(array_map)
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) {
fci.retval = &result;
fci.param_count = 1;
fci.params = zv;
fci.params = &arg;
fci.no_separation = 0;
if (Z_REFCOUNTED_P(zv)) {
Z_ADDREF_P(zv);
}
ZVAL_COPY(&arg, zv);
if (zend_call_function(&fci, &fci_cache TSRMLS_CC) != SUCCESS || Z_TYPE(result) == IS_UNDEF) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the map callback");
zval_dtor(return_value);
zval_ptr_dtor(zv);
zval_ptr_dtor(&arg);
RETURN_NULL();
} else {
zval_ptr_dtor(zv);
zval_ptr_dtor(&arg);
}
if (str_key) {
zend_hash_add_new(Z_ARRVAL_P(return_value), str_key, &result);