tony2001 Sat Jun 7 14:09:06 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/spl spl_fastarray.c Log: MFH http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_fastarray.c?r1=1.1.2.4&r2=1.1.2.5&diff_format=u Index: php-src/ext/spl/spl_fastarray.c diff -u php-src/ext/spl/spl_fastarray.c:1.1.2.4 php-src/ext/spl/spl_fastarray.c:1.1.2.5 --- php-src/ext/spl/spl_fastarray.c:1.1.2.4 Sat Jun 7 12:47:04 2008 +++ php-src/ext/spl/spl_fastarray.c Sat Jun 7 14:09:06 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_fastarray.c,v 1.1.2.4 2008/06/07 12:47:04 tony2001 Exp $ */ +/* $Id: spl_fastarray.c,v 1.1.2.5 2008/06/07 14:09:06 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -109,6 +109,7 @@ if (array->elements) { efree(array->elements); + array->elements = NULL; } } else if (size > array->size) { array->elements = erealloc(array->elements, sizeof(zval *) * size); @@ -147,16 +148,18 @@ spl_fastarray_object *intern = (spl_fastarray_object *)object; long i; - for (i = 0; i < intern->array->size; i++) { - if (intern->array->elements[i]) { - zval_ptr_dtor(&(intern->array->elements[i])); + if (intern->array) { + for (i = 0; i < intern->array->size; i++) { + if (intern->array->elements[i]) { + zval_ptr_dtor(&(intern->array->elements[i])); + } } - } - if (intern->array->elements) { - efree(intern->array->elements); + if (intern->array->elements) { + efree(intern->array->elements); + } + efree(intern->array); } - efree(intern->array); zend_object_std_dtor(&intern->std TSRMLS_CC); zval_ptr_dtor(&intern->retval); @@ -280,13 +283,20 @@ { long index; + /* we have to return NULL on error here to avoid memleak because of + * ZE duplicating uninitialized_zval_ptr */ + if (!offset) { + zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC); + return NULL; + } + index = spl_offset_convert_to_long(offset TSRMLS_CC); if (index < 0 || index >= intern->array->size) { zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC); - return &EG(uninitialized_zval_ptr); + return NULL; } else if(!intern->array->elements[index]) { - return &EG(uninitialized_zval_ptr); + return NULL; } else { return &intern->array->elements[index]; } @@ -296,6 +306,7 @@ static zval *spl_fastarray_object_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */ { spl_fastarray_object *intern; + zval **retval; intern = (spl_fastarray_object *)zend_object_store_get_object(object TSRMLS_CC); @@ -313,7 +324,11 @@ return EG(uninitialized_zval_ptr); } - return *spl_fastarray_object_read_dimension_helper(intern, offset TSRMLS_CC); + retval = spl_fastarray_object_read_dimension_helper(intern, offset TSRMLS_CC); + if (retval) { + return *retval; + } + return NULL; } /* }}} */ @@ -573,7 +588,10 @@ intern = (spl_fastarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC); value_pp = spl_fastarray_object_read_dimension_helper(intern, zindex TSRMLS_CC); - RETURN_ZVAL(*value_pp, 1, 0); + if (value_pp) { + RETURN_ZVAL(*value_pp, 1, 0); + } + RETURN_NULL(); } /* }}} */ /* {{{ proto void SplFastArray::offsetSet(mixed $index, mixed $newval) U @@ -684,6 +702,10 @@ *data = spl_fastarray_object_read_dimension_helper(intern, zindex TSRMLS_CC); + if (*data == NULL) { + *data = &EG(uninitialized_zval_ptr); + } + zval_ptr_dtor(&zindex); } /* }}} */ @@ -784,7 +806,10 @@ zval_ptr_dtor(&zindex); - RETURN_ZVAL(*value_pp, 1, 0); + if (value_pp) { + RETURN_ZVAL(*value_pp, 1, 0); + } + RETURN_NULL(); } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php