cvs: ZendEngine2 / zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h /tests bug32674.phpt

From: Date: Wed, 27 Apr 2005 06:47:09 +0000
Subject: cvs: ZendEngine2 / zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h /tests bug32674.phpt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-3598@lists.php.net to get a copy of this message
dmitry Wed Apr 27 02:47:09 2005 EDT Modified files: /ZendEngine2 zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h /ZendEngine2/tests bug32674.phpt Log: Fixed bug #32674 (exception in iterator causes crash)

http://cvs.php.net/diff.php/ZendEngine2/zend_vm_def.h?r1=1.21&r2=1.22&ty=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.21 ZendEngine2/zend_vm_def.h:1.22 --- ZendEngine2/zend_vm_def.h:1.21 Tue Apr 26 09:23:22 2005 +++ ZendEngine2/zend_vm_def.h Wed Apr 27 02:47:07 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.21 2005/04/26 13:23:22 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.22 2005/04/27 06:47:07 dmitry Exp $ */ ZEND_VM_HANDLER(1, ZEND_ADD, CONST|TMP|VAR|CV, CONST|TMP|VAR|CV) { @@ -2917,8 +2917,18 @@ iter->index = 0; if (iter->funcs->rewind) { iter->funcs->rewind(iter TSRMLS_CC); + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } is_empty = iter->funcs->valid(iter TSRMLS_CC) != SUCCESS; + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { zend_hash_internal_pointer_reset(fe_ht); if (ce) { @@ -3019,21 +3029,41 @@ /* This could cause an endless loop if index becomes zero again. * In case that ever happens we need an additional flag. */ iter->funcs->move_forward(iter TSRMLS_CC); + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } } if (!iter || (iter->index > 1 && iter->funcs->valid(iter TSRMLS_CC) == FAILURE)) { /* reached end of iteration */ + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num); ZEND_VM_CONTINUE_JMP(); } iter->funcs->get_current_data(iter, &value TSRMLS_CC); if (!value) { /* failure in get_current_data */ + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num); ZEND_VM_CONTINUE_JMP(); } if (use_key) { if (iter->funcs->get_current_key) { key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC); + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } } else { key_type = HASH_KEY_IS_LONG; int_key = iter->index; http://cvs.php.net/diff.php/ZendEngine2/zend_vm_execute.h?r1=1.23&r2=1.24&ty=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.23 ZendEngine2/zend_vm_execute.h:1.24 --- ZendEngine2/zend_vm_execute.h:1.23 Tue Apr 26 09:23:22 2005 +++ ZendEngine2/zend_vm_execute.h Wed Apr 27 02:47:07 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_execute.h,v 1.23 2005/04/26 13:23:22 dmitry Exp $ */ +/* $Id: zend_vm_execute.h,v 1.24 2005/04/27 06:47:07 dmitry Exp $ */ #define ZEND_VM_CONTINUE() return 0 @@ -1986,8 +1986,18 @@ iter->index = 0; if (iter->funcs->rewind) { iter->funcs->rewind(iter TSRMLS_CC); + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } is_empty = iter->funcs->valid(iter TSRMLS_CC) != SUCCESS; + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { zend_hash_internal_pointer_reset(fe_ht); if (ce) { @@ -4417,8 +4427,18 @@ iter->index = 0; if (iter->funcs->rewind) { iter->funcs->rewind(iter TSRMLS_CC); + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } is_empty = iter->funcs->valid(iter TSRMLS_CC) != SUCCESS; + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { zend_hash_internal_pointer_reset(fe_ht); if (ce) { @@ -7506,8 +7526,18 @@ iter->index = 0; if (iter->funcs->rewind) { iter->funcs->rewind(iter TSRMLS_CC); + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } is_empty = iter->funcs->valid(iter TSRMLS_CC) != SUCCESS; + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { zend_hash_internal_pointer_reset(fe_ht); if (ce) { @@ -7608,21 +7638,41 @@ /* This could cause an endless loop if index becomes zero again. * In case that ever happens we need an additional flag. */ iter->funcs->move_forward(iter TSRMLS_CC); + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } } if (!iter || (iter->index > 1 && iter->funcs->valid(iter TSRMLS_CC) == FAILURE)) { /* reached end of iteration */ + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num); ZEND_VM_CONTINUE_JMP(); } iter->funcs->get_current_data(iter, &value TSRMLS_CC); if (!value) { /* failure in get_current_data */ + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num); ZEND_VM_CONTINUE_JMP(); } if (use_key) { if (iter->funcs->get_current_key) { key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC); + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } } else { key_type = HASH_KEY_IS_LONG; int_key = iter->index; @@ -18529,8 +18579,18 @@ iter->index = 0; if (iter->funcs->rewind) { iter->funcs->rewind(iter TSRMLS_CC); + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } is_empty = iter->funcs->valid(iter TSRMLS_CC) != SUCCESS; + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { zend_hash_internal_pointer_reset(fe_ht); if (ce) { @@ -30995,8 +31055,18 @@ iter->index = 0; if (iter->funcs->rewind) { iter->funcs->rewind(iter TSRMLS_CC); + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } is_empty = iter->funcs->valid(iter TSRMLS_CC) != SUCCESS; + if (EG(exception)) { + array_ptr->refcount--; + zval_ptr_dtor(&array_ptr); + ZEND_VM_NEXT_OPCODE(); + } } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { zend_hash_internal_pointer_reset(fe_ht); if (ce) { @@ -31097,21 +31167,41 @@ /* This could cause an endless loop if index becomes zero again. * In case that ever happens we need an additional flag. */ iter->funcs->move_forward(iter TSRMLS_CC); + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } } if (!iter || (iter->index > 1 && iter->funcs->valid(iter TSRMLS_CC) == FAILURE)) { /* reached end of iteration */ + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num); ZEND_VM_CONTINUE_JMP(); } iter->funcs->get_current_data(iter, &value TSRMLS_CC); if (!value) { /* failure in get_current_data */ + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } ZEND_VM_SET_OPCODE(EX(op_array)->opcodes+opline->op2.u.opline_num); ZEND_VM_CONTINUE_JMP(); } if (use_key) { if (iter->funcs->get_current_key) { key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC); + if (EG(exception)) { + array->refcount--; + zval_ptr_dtor(&array); + ZEND_VM_NEXT_OPCODE(); + } } else { key_type = HASH_KEY_IS_LONG; int_key = iter->index; http://cvs.php.net/diff.php/ZendEngine2/zend_vm_opcodes.h?r1=1.10&r2=1.11&ty=u Index: ZendEngine2/zend_vm_opcodes.h diff -u ZendEngine2/zend_vm_opcodes.h:1.10 ZendEngine2/zend_vm_opcodes.h:1.11 --- ZendEngine2/zend_vm_opcodes.h:1.10 Tue Apr 26 09:23:23 2005 +++ ZendEngine2/zend_vm_opcodes.h Wed Apr 27 02:47:08 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_opcodes.h,v 1.10 2005/04/26 13:23:23 dmitry Exp $ */ +/* $Id: zend_vm_opcodes.h,v 1.11 2005/04/27 06:47:08 dmitry Exp $ */ #define ZEND_NOP 0 #define ZEND_ADD 1 http://cvs.php.net/diff.php/ZendEngine2/tests/bug32674.phpt?r1=1.1&r2=1.2&ty=u Index: ZendEngine2/tests/bug32674.phpt diff -u /dev/null ZendEngine2/tests/bug32674.phpt:1.2 --- /dev/null Wed Apr 27 02:47:08 2005 +++ ZendEngine2/tests/bug32674.phpt Wed Apr 27 02:47:08 2005 @@ -0,0 +1,62 @@ +--TEST-- +Bug #32674 exception in iterator causes crash +--FILE-- +<?php +class collection implements Iterator { + + private $_elements = array(); + + public function __construct() { + } + + public function rewind() { + reset($this->_elements); + } + + public function count() { + return count($this->_elements); + } + + public function current() { + $element = current($this->_elements); + return $element; + } + + public function next() { + $element = next($this->_elements); + return $element; + } + + public function key() { + $this->_fillCollection(); + $element = key($this->_elements); + return $element; + } + + public function valid() { + throw new Exception('shit happend'); + + return ($this->current() !== false); + } +} + +class class2 { + public $dummy; +} + +$obj = new class2(); +$col = new collection(); + +try { + foreach($col as $co) { + //irrelevant + } + echo 'shouldn`t get here'; + //$dummy = 'this will not crash'; + $obj->dummy = 'this will crash'; +} catch (Exception $e) { + echo "ok\n"; +} +?> +--EXPECT-- +ok
« previous php.zend-engine.cvs (#3598) next »