com php-src: Fix leak on assignment to illegal AO offset: ext/spl/spl_array.c ext/spl/tests/ArrayObject_illegal _offset_leak.phpt

From: Date: Wed, 24 Feb 2016 16:39:16 +0000
Subject: com php-src: Fix leak on assignment to illegal AO offset: ext/spl/spl_array.c ext/spl/tests/ArrayObject_illegal _offset_leak.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-91153@lists.php.net to get a copy of this message
Commit: eb885e9d6ebc6670d1ccc6d5c0fa26e411ffb0fb Author: Nikita Popov <nikic@php.net> Wed, 24 Feb 2016 17:39:16 +0100 Parents: ea02f5765608c13cb92b5b7879878b981c99b33e Branches: PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=eb885e9d6ebc6670d1ccc6d5c0fa26e411ffb0fb Log: Fix leak on assignment to illegal AO offset Changed paths: M ext/spl/spl_array.c A ext/spl/tests/ArrayObject_illegal_offset_leak.phpt Diff: diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 9ddd38b..0740c06 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -439,19 +439,16 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval return; } + if (Z_REFCOUNTED_P(value)) { + Z_ADDREF_P(value); + } + if (!offset) { ht = spl_array_get_hash_table(intern); - if (Z_REFCOUNTED_P(value)) { - Z_ADDREF_P(value); - } zend_hash_next_index_insert(ht, value); return; } - if (Z_REFCOUNTED_P(value)) { - Z_ADDREF_P(value); - } - try_again: switch (Z_TYPE_P(offset)) { case IS_STRING: @@ -485,6 +482,7 @@ num_index: goto try_again; default: zend_error(E_WARNING, "Illegal offset type"); + zval_ptr_dtor(value); return; } } /* }}} */ diff --git a/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt b/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt new file mode 100644 index 0000000..42c649d --- /dev/null +++ b/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt @@ -0,0 +1,11 @@ +--TEST-- +Assignments to illegal ArrayObject offsets shouldn't leak +--FILE-- +<?php + +$ao = new ArrayObject([1, 2, 3]); +$ao[[]] = new stdClass; + +?> +--EXPECTF-- +Warning: Illegal offset type in %s on line %d

« previous php.cvs (#91153) next »