From: Etienne Kneuss Date: Sun, 19 Oct 2008 18:00:42 +0000 (+0000) Subject: MFB: Fix #46317 (Iterator class not properly checked) X-Git-Tag: php-5.2.7RC2~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c31e0c803ecf6950c3d0070f3d7df9f9c9501f5f;p=php MFB: Fix #46317 (Iterator class not properly checked) --- diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 2760ceaace..5e70473bc2 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -910,9 +910,7 @@ SPL_METHOD(Array, __construct) spl_array_object *intern; zval **array; long ar_flags = 0; - char *class_name; - int class_name_len; - zend_class_entry ** pce_get_iterator; + zend_class_entry * ce_get_iterator = spl_ce_Iterator; if (ZEND_NUM_ARGS() == 0) { return; /* nothing to do */ @@ -921,7 +919,7 @@ SPL_METHOD(Array, __construct) intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|ls", &array, &ar_flags, &class_name, &class_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|lC", &array, &ar_flags, &ce_get_iterator) == FAILURE) { php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); return; } @@ -931,12 +929,7 @@ SPL_METHOD(Array, __construct) } if (ZEND_NUM_ARGS() > 2) { - if (zend_lookup_class(class_name, class_name_len, &pce_get_iterator TSRMLS_CC) == FAILURE) { - zend_throw_exception(spl_ce_InvalidArgumentException, "A class that implements Iterator must be specified", 0 TSRMLS_CC); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - intern->ce_get_iterator = *pce_get_iterator; + intern->ce_get_iterator = ce_get_iterator; } ar_flags &= ~SPL_ARRAY_INT_MASK; @@ -989,21 +982,14 @@ SPL_METHOD(Array, setIteratorClass) { zval *object = getThis(); spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - char *class_name; - int class_name_len; - zend_class_entry ** pce_get_iterator; + zend_class_entry * ce_get_iterator = spl_ce_Iterator; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &class_name, &class_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "C", &ce_get_iterator) == FAILURE) { php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); return; } - if (zend_lookup_class(class_name, class_name_len, &pce_get_iterator TSRMLS_CC) == FAILURE) { - zend_throw_exception(spl_ce_InvalidArgumentException, "A class that implements Iterator must be specified", 0 TSRMLS_CC); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - intern->ce_get_iterator = *pce_get_iterator; + intern->ce_get_iterator = ce_get_iterator; } /* }}} */ diff --git a/ext/spl/tests/arrayObject___construct_error1.phpt b/ext/spl/tests/arrayObject___construct_error1.phpt index 789b08763c..21c312d2d0 100644 --- a/ext/spl/tests/arrayObject___construct_error1.phpt +++ b/ext/spl/tests/arrayObject___construct_error1.phpt @@ -1,7 +1,5 @@ --TEST-- SPL: ArrayObject::__construct with bad iterator. ---XFAIL-- -See bug http://bugs.php.net/bug.php?id=46317 --FILE-- 2 c=>3 string(113) "ArrayObject::__construct() expects parameter 3 to be a class name derived from Iterator, 'nonExistentClass' given" -string(105) "ArrayObject::__construct() expects parameter 3 to be a class name derived from Iterator, 'stdClass' given" \ No newline at end of file +string(105) "ArrayObject::__construct() expects parameter 3 to be a class name derived from Iterator, 'stdClass' given"