]> granicus.if.org Git - php/commitdiff
MFB: fix #44214
authorNuno Lopes <nlopess@php.net>
Sat, 8 Mar 2008 13:14:02 +0000 (13:14 +0000)
committerNuno Lopes <nlopess@php.net>
Sat, 8 Mar 2008 13:14:02 +0000 (13:14 +0000)
ext/pcre/php_pcre.c
ext/pcre/tests/bug44214.phpt [new file with mode: 0644]
ext/pcre/tests/bug44214_2.phpt [new file with mode: 0644]

index 98b2a6580d9e97df9cece5d30dd4b229d26b92ef..36b534db9a9e7e0e6d892450f6fa7b5a8c0d5e1b 100644 (file)
@@ -969,8 +969,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 (file)
index 0000000..90e4c86
--- /dev/null
@@ -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 (file)
index 0000000..d78846c
--- /dev/null
@@ -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"
+}