Fix #78853: preg_match() may return integer > 1

Commit 54ebebd[1] optimized the match loop, but for this case it has
been overlooked, that we must only loop if we're doing global matching.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=54ebebd686255c5f124af718c966edb392782d4a>
This commit is contained in:
Christoph M. Becker 2019-11-22 19:21:43 +01:00
parent e981f5af51
commit e1da72bdf1
3 changed files with 16 additions and 1 deletions

3
NEWS
View file

@ -14,6 +14,9 @@ PHP NEWS
. Fixed $x = (bool)$x; with opcache (should emit undeclared variable notice). . Fixed $x = (bool)$x; with opcache (should emit undeclared variable notice).
(Tyson Andre) (Tyson Andre)
- PCRE:
. Fixed bug #78853 (preg_match() may return integer > 1). (cmb)
- Standard: - Standard:
. Fixed bug #78759 (array_search in $GLOBALS). (Nikita) . Fixed bug #78759 (array_search in $GLOBALS). (Nikita)

View file

@ -1344,7 +1344,11 @@ matched:
count = pcre2_match(pce->re, (PCRE2_SPTR)subject, subject_len, start_offset2, count = pcre2_match(pce->re, (PCRE2_SPTR)subject, subject_len, start_offset2,
PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED, match_data, mctx); PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED, match_data, mctx);
if (count >= 0) { if (count >= 0) {
if (global) {
goto matched; goto matched;
} else {
break;
}
} else if (count == PCRE2_ERROR_NOMATCH) { } else if (count == PCRE2_ERROR_NOMATCH) {
/* If we previously set PCRE2_NOTEMPTY_ATSTART after a null match, /* If we previously set PCRE2_NOTEMPTY_ATSTART after a null match,
this is not necessarily the end. We need to advance this is not necessarily the end. We need to advance

View file

@ -0,0 +1,8 @@
--TEST--
Bug #78853 (preg_match() may return integer > 1)
--FILE--
<?php
var_dump(preg_match('/^|\d{1,2}$/', "7"));
?>
--EXPECT--
int(1)