From: Antony Dovgal Date: Thu, 20 Sep 2007 08:10:20 +0000 (+0000) Subject: if one of regular expressions in the array fails, return NULL right away X-Git-Tag: RELEASE_2_0_0a1~1786 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b17f226b9443c71ea8ebe82d37bf8842fea4022;p=php if one of regular expressions in the array fails, return NULL right away this fixes "String is not zero-terminated" error and makes the behaviour consistent with regexps passed as strings --- diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 202f12cdde..16d2195ac0 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -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 index 0000000000..befca54aaa --- /dev/null +++ b/ext/pcre/tests/006.phpt @@ -0,0 +1,28 @@ +--TEST-- +preg_replace() with array of failing regular expressions +--FILE-- + +--EXPECTF-- +string(58) "[CODE]<td align="$stylevar[right]">[/CODE]" +NULL +string(58) "[CODE]<td align="$stylevar[right]">[/CODE]" +NULL +Done +--UEXPECTF-- +unicode(58) "[CODE]<td align="$stylevar[right]">[/CODE]" +NULL +unicode(58) "[CODE]<td align="$stylevar[right]">[/CODE]" +NULL +Done