summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2008-03-08 13:01:59 +0000
committerNuno Lopes <nlopess@php.net>2008-03-08 13:01:59 +0000
commit634fef42d64ceb435e15c6a08139aab3bf7403b8 (patch)
tree23d50f4da426a1f939c76c8fc9daf4388a5b7b83
parent11bbb0165a299fd1d8e6fca314539c3d221d4eb1 (diff)
downloadphp-git-634fef42d64ceb435e15c6a08139aab3bf7403b8.tar.gz
fix bug #44214: crash with preg_replace_callback and global variables
-rw-r--r--ext/pcre/php_pcre.c4
-rw-r--r--ext/pcre/tests/bug44214.phpt31
-rw-r--r--ext/pcre/tests/bug44214_2.phpt25
3 files changed, 58 insertions, 2 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 512c88da71..5a32bd0d81 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -841,8 +841,8 @@ static int preg_do_repl_func(zval *function, char *subject, int *offsets, char *
result_len = offsets[1] - offsets[0];
*result = estrndup(&subject[offsets[0]], result_len);
}
- zval_dtor(subpats);
- FREE_ZVAL(subpats);
+
+ zval_ptr_dtor(&subpats);
return result_len;
}
diff --git a/ext/pcre/tests/bug44214.phpt b/ext/pcre/tests/bug44214.phpt
new file mode 100644
index 0000000000..90e4c86453
--- /dev/null
+++ b/ext/pcre/tests/bug44214.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Bug #44214 (crash with preg_replace_callback() and global variable)
+--FILE--
+<?php
+$string = 'aaa bbb ccc ddd eee ccc aaa bbb';
+
+$array = array();
+
+function myCallBack( $match ) {
+ global $array;
+ $array[] = $match;
+ return 'xxx';
+}
+
+var_dump(preg_replace_callback( '`a+`', 'myCallBack', $string));
+var_dump($array);
+?>
+--EXPECT--
+string(31) "xxx bbb ccc ddd eee ccc xxx bbb"
+array(2) {
+ [0]=>
+ array(1) {
+ [0]=>
+ string(3) "aaa"
+ }
+ [1]=>
+ array(1) {
+ [0]=>
+ string(3) "aaa"
+ }
+}
diff --git a/ext/pcre/tests/bug44214_2.phpt b/ext/pcre/tests/bug44214_2.phpt
new file mode 100644
index 0000000000..d78846cc83
--- /dev/null
+++ b/ext/pcre/tests/bug44214_2.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug #44214-2 (crash with preg_replace_callback() and global variable)
+--FILE--
+<?php
+$string = 'aaa bbb ccc ddd eee ccc aaa bbb';
+
+$array = array();
+
+function myCallBack( $match ) {
+ global $array;
+ $array[] = $match[0];
+ return 'xxx';
+}
+
+var_dump(preg_replace_callback( '`a+`', 'myCallBack', $string));
+var_dump($array);
+?>
+--EXPECT--
+string(31) "xxx bbb ccc ddd eee ccc xxx bbb"
+array(2) {
+ [0]=>
+ string(3) "aaa"
+ [1]=>
+ string(3) "aaa"
+}