]> granicus.if.org Git - php/commitdiff
if one of regular expressions in the array fails, return NULL right away
authorAntony Dovgal <tony2001@php.net>
Thu, 20 Sep 2007 08:10:20 +0000 (08:10 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 20 Sep 2007 08:10:20 +0000 (08:10 +0000)
this fixes "String is not zero-terminated" error and makes the behaviour consistent with regexps passed as strings

ext/pcre/php_pcre.c
ext/pcre/tests/006.phpt [new file with mode: 0644]

index 202f12cddede88124f6166f46abcd8366a3bb5c3..16d2195ac0aeea3bfff4b0259b3f3f8238d187d2 100644 (file)
@@ -1367,8 +1367,11 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject,
                                efree(subject_value);
                                subject_value = result;
                                subject_len = *result_len;
+                       } else {
+                               efree(subject_value);
+                               return NULL;
                        }
-                       
+
                        zend_hash_move_forward(Z_ARRVAL_P(regex));
                }
 
diff --git a/ext/pcre/tests/006.phpt b/ext/pcre/tests/006.phpt
new file mode 100644 (file)
index 0000000..befca54
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+preg_replace() with array of failing regular expressions
+--FILE--
+<?php
+
+$text = '[CODE]&lt;td align=&quot;$stylevar[right]&quot;&gt;[/CODE]';
+$result = preg_replace(array('#\[(right)\](((?R)|[^[]+?|\[)*)\[/\\1\]#siU', '#\[(right)\](((?R)|[^[]+?|\[)*)\[/\\1\]#siU'), '', $text);
+var_dump($text);
+var_dump($result);
+
+$result = preg_replace('#\[(right)\](((?R)|[^[]+?|\[)*)\[/\\1\]#siU', '', $text);
+var_dump($text);
+var_dump($result);
+
+echo "Done\n";
+?>
+--EXPECTF--    
+string(58) "[CODE]&lt;td align=&quot;$stylevar[right]&quot;&gt;[/CODE]"
+NULL
+string(58) "[CODE]&lt;td align=&quot;$stylevar[right]&quot;&gt;[/CODE]"
+NULL
+Done
+--UEXPECTF--
+unicode(58) "[CODE]&lt;td align=&quot;$stylevar[right]&quot;&gt;[/CODE]"
+NULL
+unicode(58) "[CODE]&lt;td align=&quot;$stylevar[right]&quot;&gt;[/CODE]"
+NULL
+Done