Skip to content

Fixed bug #62987 (Assigning to ArrayObject[null][something] overrides al... #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ static zval **spl_array_get_dimension_ptr_ptr(int check_inherited, zval *object,
}

switch(Z_TYPE_P(offset)) {
case IS_NULL:
Z_STRVAL_P(offset) = "";
Z_STRLEN_P(offset) = 0;
/* Fall Through */
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) {
Expand Down Expand Up @@ -367,8 +371,8 @@ static zval **spl_array_get_dimension_ptr_ptr(int check_inherited, zval *object,
}
break;
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);
}
} /* }}} */

Expand Down
46 changes: 46 additions & 0 deletions ext/spl/tests/bug62987.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
Bug #62987 (Assigning to ArrayObject[null][something] overrides all undefined variables)
--FILE--
<?php

$a = new ArrayObject();

$b = array();

$a[null]['hurr'] = 'durr';

$d = array();
var_dump($d['non-exist-key']);

$undefine = 'will null be overwrited?';

var_dump($what_ever);
var_dump($a['non-exist-key']);
var_dump($d['non-exist-key']);

var_dump($a);
?>
===DONE===
--EXPECTF--
Notice: Undefined index: non-exist-key in %sbug62987.php on line %d
NULL

Notice: Undefined variable: what_ever in %sbug62987.php on line %d
NULL

Notice: Undefined index: non-exist-key in %sbug62987.php on line %d
NULL

Notice: Undefined index: non-exist-key in %sbug62987.php on line %d
NULL
object(ArrayObject)#%d (%d) {
["storage":"ArrayObject":private]=>
array(1) {
[""]=>
array(1) {
["hurr"]=>
string(4) "durr"
}
}
}
===DONE===