From: Marcus Boerger Date: Tue, 4 Nov 2003 22:07:59 +0000 (+0000) Subject: Prevent some SEGV's when Exceptions are thorown inside iterators. X-Git-Tag: php-5.0.0b3RC1~766 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9d13098e732e89873d49353c2dd901dd11aa583;p=php Prevent some SEGV's when Exceptions are thorown inside iterators. --- diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 1bbd28108d..b7758c5252 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2625,7 +2625,7 @@ int zend_do_fcall_common_helper(ZEND_OPCODE_HANDLER_ARGS) } if (EG(This)) { - if (EG(exception) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { + if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { EG(This)->refcount--; zval_ptr_dtor(&EG(This)); } else if (should_change_scope) { @@ -3632,7 +3632,8 @@ int zend_fe_fetch_handler(ZEND_OPCODE_HANDLER_ARGS) break; case ZEND_ITER_OBJECT: - if (iter->funcs->has_more(iter TSRMLS_CC) == FAILURE) { + /* !iter happens from exception */ + if (!iter || iter->funcs->has_more(iter TSRMLS_CC) == FAILURE) { /* reached end of iteration */ EX(opline) = op_array->opcodes+EX(opline)->op2.u.opline_num; return 0; /* CHECK_ME */ diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index 082653fedf..2de36c656e 100755 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -131,16 +131,21 @@ static void zend_user_dtor(zend_object_iterator *_iter TSRMLS_DC) /* {{{ zend_user_has_more */ static int zend_user_has_more(zend_object_iterator *_iter TSRMLS_DC) { - zend_user_iterator *iter = (zend_user_iterator*)_iter; - zval *object = (zval*)iter->it.data; - zval *more; - int result; - - zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_has_more, "hasmore", &more); - result = i_zend_is_true(more); - zval_dtor(more); - FREE_ZVAL(more); - return result ? SUCCESS : FAILURE; + if (_iter) { + zend_user_iterator *iter = (zend_user_iterator*)_iter; + zval *object = (zval*)iter->it.data; + zval *more; + int result; + + zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_has_more, "hasmore", &more); + if (more) { + result = i_zend_is_true(more); + zval_dtor(more); + FREE_ZVAL(more); + return result ? SUCCESS : FAILURE; + } + } + return FAILURE; } /* }}} */