diff options
| author | Xinchen Hui <laruence@php.net> | 2012-09-01 14:27:09 +0800 |
|---|---|---|
| committer | Xinchen Hui <laruence@php.net> | 2012-09-01 14:27:09 +0800 |
| commit | 863e7e0acbe284d5c7738fa9c601023ad5773d3f (patch) | |
| tree | ad17510ddf5fb7f4c24c09f368c2db440010e5b3 | |
| parent | e658a91b3d826ea4104b17f3a6123c1e9f3aee86 (diff) | |
| parent | 67d7d03f00cb3185a4d5958ab7a4b063fc33405c (diff) | |
| download | php-git-863e7e0acbe284d5c7738fa9c601023ad5773d3f.tar.gz | |
Merge branch 'PHP-5.3' into PHP-5.4
Conflicts:
ext/spl/spl_array.c
| -rw-r--r-- | NEWS | 2 | ||||
| -rwxr-xr-x | ext/spl/spl_array.c | 74 | ||||
| -rw-r--r-- | ext/spl/tests/bug62978.phpt | 50 |
3 files changed, 89 insertions, 37 deletions
@@ -64,6 +64,8 @@ PHP NEWS when close handler call exit). (Laruence) - SPL: + . Bug #62987 (Assigning to ArrayObject[null][something] overrides all + undefined variables). (Laruence) . Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray) (Laruence) . Implemented FR #62840 (Add sort flag to ArrayObject::ksort). (Laruence) diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 1e4577a3f9..0b3b5a3e54 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -306,41 +306,41 @@ static zval **spl_array_get_dimension_ptr_ptr(int check_inherited, zval *object, long index; HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); -/* We cannot get the pointer pointer so we don't allow it here for now - if (check_inherited && intern->fptr_offset_get) { - return zend_call_method_with_1_params(&object, Z_OBJCE_P(object), &intern->fptr_offset_get, "offsetGet", NULL, offset); - }*/ - if (!offset) { return &EG(uninitialized_zval_ptr); } if ((type == BP_VAR_W || type == BP_VAR_RW) && (ht->nApplyCount > 0)) { zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); - return &EG(uninitialized_zval_ptr);; + return &EG(error_zval_ptr);; } switch(Z_TYPE_P(offset)) { + case IS_NULL: + Z_STRVAL_P(offset) = ""; + Z_STRLEN_P(offset) = 0; case IS_STRING: if (zend_symtable_find(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &retval) == FAILURE) { - if (type == BP_VAR_W || type == BP_VAR_RW) { - zval *value; - ALLOC_INIT_ZVAL(value); - zend_symtable_update(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void**)&value, sizeof(void*), NULL); - if (zend_symtable_find(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &retval) != FAILURE) { - return retval; - } else { - return &EG(uninitialized_zval_ptr); + switch (type) { + case BP_VAR_R: + zend_error(E_NOTICE, "Undefined index: %s", Z_STRVAL_P(offset)); + case BP_VAR_UNSET: + case BP_VAR_IS: + retval = &EG(uninitialized_zval_ptr); + break; + case BP_VAR_RW: + zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); + case BP_VAR_W: { + zval *value; + ALLOC_INIT_ZVAL(value); + zend_symtable_update(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void**)&value, sizeof(void*), (void **)&retval); } - } else { - zend_error(E_NOTICE, "Undefined index: %s", Z_STRVAL_P(offset)); - return &EG(uninitialized_zval_ptr); } - } else { - return retval; } - case IS_DOUBLE: + return retval; case IS_RESOURCE: + zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_LVAL_P(offset), Z_LVAL_P(offset)); + case IS_DOUBLE: case IS_BOOL: case IS_LONG: if (offset->type == IS_DOUBLE) { @@ -349,26 +349,27 @@ static zval **spl_array_get_dimension_ptr_ptr(int check_inherited, zval *object, index = Z_LVAL_P(offset); } if (zend_hash_index_find(ht, index, (void **) &retval) == FAILURE) { - if (type == BP_VAR_W || type == BP_VAR_RW) { - zval *value; - ALLOC_INIT_ZVAL(value); - zend_hash_index_update(ht, index, (void**)&value, sizeof(void*), NULL); - if (zend_hash_index_find(ht, index, (void **) &retval) != FAILURE) { - return retval; - } else { - return &EG(uninitialized_zval_ptr); - } - } else { - zend_error(E_NOTICE, "Undefined offset: %ld", index); - return &EG(uninitialized_zval_ptr); + switch (type) { + case BP_VAR_R: + zend_error(E_NOTICE, "Undefined offset: %ld", index); + case BP_VAR_UNSET: + case BP_VAR_IS: + retval = &EG(uninitialized_zval_ptr); + break; + case BP_VAR_RW: + zend_error(E_NOTICE, "Undefined offset: %ld", index); + case BP_VAR_W: { + zval *value; + ALLOC_INIT_ZVAL(value); + zend_hash_index_update(ht, index, (void**)&value, sizeof(void*), (void **)&retval); + } } - } else { - return retval; } - break; + return retval; default: zend_error(E_WARNING, "Illegal offset type"); - return &EG(uninitialized_zval_ptr); + return (type == BP_VAR_W || type == BP_VAR_RW) ? + &EG(error_zval_ptr) : &EG(uninitialized_zval_ptr); } } /* }}} */ @@ -713,7 +714,6 @@ SPL_METHOD(Array, offsetSet) spl_array_write_dimension_ex(0, getThis(), index, value TSRMLS_CC); } /* }}} */ - void spl_array_iterator_append(zval *object, zval *append_value TSRMLS_DC) /* {{{ */ { spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); diff --git a/ext/spl/tests/bug62978.phpt b/ext/spl/tests/bug62978.phpt new file mode 100644 index 0000000000..94068d5604 --- /dev/null +++ b/ext/spl/tests/bug62978.phpt @@ -0,0 +1,50 @@ +--TEST-- +Bug #62987 (Assigning to ArrayObject[null][something] overrides all undefined variables) +--FILE-- +<?php +$a = new ArrayObject(); + +$b = array(); + +$a[null]['hurr'] = 'durr'; + +var_dump($a['epic_magic']); +var_dump($b['epic_magic']); +var_dump($c['epic_magic']); // Undefined var!! + +$d = array(); +var_dump($a['epic_magic']); // more magic! +var_dump($d['epic_magic']); + +$e = 'srsly?'; +var_dump($a['epic_magic']); // srsly. +var_dump(isset($a['epic_magic'])); + +$fp = fopen(__FILE__, 'r'); +var_dump($a[$fp]); + +fclose($fp); +--EXPECTF-- +Notice: Undefined index: epic_magic in %sbug62978.php on line %d +NULL + +Notice: Undefined index: epic_magic in %sbug62978.php on line %d +NULL + +Notice: Undefined variable: c in %sbug62978.php on line %d +NULL + +Notice: Undefined index: epic_magic in %sbug62978.php on line %d +NULL + +Notice: Undefined index: epic_magic in %sbug62978.php on line %d +NULL + +Notice: Undefined index: epic_magic in %sbug62978.php on line %d +NULL +bool(false) + +Strict Standards: Resource ID#%d used as offset, casting to integer (%d) in %sbug62978.php on line %d + +Notice: Undefined offset: %d in %sbug62978.php on line %d +NULL |
