com php-src: Fix #73612: preg_*() may leak memory : NEWS ext/pcre/php_pcre.c ext/pcre/tests/bug73 612.phpt

From: Date: Sat, 26 Nov 2016 14:34:27 +0000
Subject: com php-src: Fix #73612: preg_*() may leak memory : NEWS ext/pcre/php_pcre.c ext/pcre/tests/bug73 612.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-96052@lists.php.net to get a copy of this message
Commit: 003727d851da770c60555a2aecf6d82497b04f42 Author: Christoph M. Becker <cmbecker69@gmx.de> Sat, 26 Nov 2016 15:34:27 +0100 Parents: 8be94d46f836a886d85b9a813b241a7f26649020 Branches: PHP-7.0 PHP-7..1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=003727d851da770c60555a2aecf6d82497b04f42 Log: Fix #73612: preg_*() may leak memory We have to make sure that collectible zvals end up in the GC root buffer, to avoid memory leaks. Bugs: https://bugs.php.net/73612 Changed paths: M NEWS M ext/pcre/php_pcre.c A ext/pcre/tests/bug73612.phpt Diff: diff --git a/NEWS b/NEWS index 9bffebb..9226c51 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ PHP NEWS . Fixed bug #73585 (Logging of "Internal Zend error - Missing class information" missing class name). (Laruence) +- PCRE: + . Fixed bug #73612 (preg_*() may leak memory). (cmb) + 08 Dec 2016 PHP 7.0.14 - Core: diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 8601b73..af1916a 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -726,7 +726,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec /* Overwrite the passed-in value for subpatterns with an empty array. */ if (subpats != NULL) { - zval_dtor(subpats); + zval_ptr_dtor(subpats); array_init(subpats); } @@ -1592,7 +1592,7 @@ static PHP_FUNCTION(preg_replace) replace_count = preg_replace_impl(return_value, regex, replace, subject, limit, 0, 0); if (zcount) { - zval_dtor(zcount); + zval_ptr_dtor(zcount); ZVAL_LONG(zcount, replace_count); } } @@ -1627,7 +1627,7 @@ static PHP_FUNCTION(preg_replace_callback) replace_count = preg_replace_impl(return_value, regex, replace, subject, limit, 1, 0); if (zcount) { - zval_dtor(zcount); + zval_ptr_dtor(zcount); ZVAL_LONG(zcount, replace_count); } } @@ -1689,7 +1689,7 @@ static PHP_FUNCTION(preg_replace_callback_array) } ZEND_HASH_FOREACH_END(); if (zcount) { - zval_dtor(zcount); + zval_ptr_dtor(zcount); ZVAL_LONG(zcount, replace_count); } } @@ -1720,7 +1720,7 @@ static PHP_FUNCTION(preg_filter) replace_count = preg_replace_impl(return_value, regex, replace, subject, limit, 0, 1); if (zcount) { - zval_dtor(zcount); + zval_ptr_dtor(zcount); ZVAL_LONG(zcount, replace_count); } } diff --git a/ext/pcre/tests/bug73612.phpt b/ext/pcre/tests/bug73612.phpt new file mode 100644 index 0000000..707e10b --- /dev/null +++ b/ext/pcre/tests/bug73612.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #73612 (preg_*() may leak memory) +--FILE-- +<?php +$obj = new stdClass; +$obj->obj = $obj; +preg_match('/./', 'x', $obj); + +$obj = new stdClass; +$obj->obj = $obj; +preg_replace('/./', '', 'x', -1, $obj); + +$obj = new stdClass; +$obj->obj = $obj; +preg_replace_callback('/./', 'count', 'x', -1, $obj); + +$obj = new stdClass; +$obj->obj = $obj; +preg_replace_callback_array(['/./' => 'count'], 'x', -1, $obj); + +$obj = new stdClass; +$obj->obj = $obj; +preg_filter('/./', '', 'x', -1, $obj); +?> +===DONE=== +--EXPECT-- +===DONE===

« previous php.cvs (#96052) next »