felipe Tue Jun 16 02:53:50 2009 UTC Added files: /php-src/ext/wddx/tests bug48562.phpt
Modified files: /php-src/ext/wddx wddx.c Log: - Fixed bug #48562 (Reference recursion causes segfault when used in wddx_serialize_vars()) http://cvs.php.net/viewvc.cgi/php-src/ext/wddx/wddx.c?r1=1.163&r2=1.164&diff_format=u Index: php-src/ext/wddx/wddx.c diff -u php-src/ext/wddx/wddx.c:1.163 php-src/ext/wddx/wddx.c:1.164 --- php-src/ext/wddx/wddx.c:1.163 Tue May 19 16:32:22 2009 +++ php-src/ext/wddx/wddx.c Tue Jun 16 02:53:49 2009 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: wddx.c,v 1.163 2009/05/19 16:32:22 kalle Exp $ */ +/* $Id: wddx.c,v 1.164 2009/06/16 02:53:49 felipe Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -700,13 +700,27 @@ php_wddx_serialize_var(packet, *val, Z_STRVAL_P(name_var), Z_STRLEN_P(name_var) TSRMLS_CC); } } else if (Z_TYPE_P(name_var) == IS_ARRAY || Z_TYPE_P(name_var) == IS_OBJECT) { + int is_array = Z_TYPE_P(name_var) == IS_ARRAY; + target_hash = HASH_OF(name_var); + if (is_array && target_hash->nApplyCount > 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); + return; + } + zend_hash_internal_pointer_reset(target_hash); while(zend_hash_get_current_data(target_hash, (void**)&val) == SUCCESS) { + if (is_array) { + target_hash->nApplyCount++; + } + php_wddx_add_var(packet, *val); - + + if (is_array) { + target_hash->nApplyCount--; + } zend_hash_move_forward(target_hash); } } http://cvs.php.net/viewvc.cgi/php-src/ext/wddx/tests/bug48562.phpt?view=markup&rev=1.1 Index: php-src/ext/wddx/tests/bug48562.phpt +++ php-src/ext/wddx/tests/bug48562.phpt --TEST-- Bug #48562 (Reference recursion causes segfault when used in wddx_serialize_vars()) --FILE-- <?php $foo = 'bar'; $a['x'] = 'foo'; $a['x'] = &$a; var_dump(wddx_serialize_vars($a)); $a['x'] = 'foo'; $a['x'] = $a; var_dump(wddx_serialize_vars($a)); ?> --EXPECTF-- Warning: wddx_serialize_vars(): recursion detected in %s on line %d string(78) "<wddxPacket version='1.0'><header/><data><struct></struct></data></wddxPacket>" string(120) "<wddxPacket version='1.0'><header/><data><struct><var name='foo'><string>bar</string></var></struct></data></wddxPacket>" -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php