Skip to content

Commit e1da72b

Browse files
committed
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>
1 parent e981f5a commit e1da72b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ PHP NEWS
1414
. Fixed $x = (bool)$x; with opcache (should emit undeclared variable notice).
1515
(Tyson Andre)
1616

17+
- PCRE:
18+
. Fixed bug #78853 (preg_match() may return integer > 1). (cmb)
19+
1720
- Standard:
1821
. Fixed bug #78759 (array_search in $GLOBALS). (Nikita)
1922

ext/pcre/php_pcre.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,11 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, size_t sub
13441344
count = pcre2_match(pce->re, (PCRE2_SPTR)subject, subject_len, start_offset2,
13451345
PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED, match_data, mctx);
13461346
if (count >= 0) {
1347-
goto matched;
1347+
if (global) {
1348+
goto matched;
1349+
} else {
1350+
break;
1351+
}
13481352
} else if (count == PCRE2_ERROR_NOMATCH) {
13491353
/* If we previously set PCRE2_NOTEMPTY_ATSTART after a null match,
13501354
this is not necessarily the end. We need to advance

ext/pcre/tests/bug78853.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Bug #78853 (preg_match() may return integer > 1)
3+
--FILE--
4+
<?php
5+
var_dump(preg_match('/^|\d{1,2}$/', "7"));
6+
?>
7+
--EXPECT--
8+
int(1)

0 commit comments

Comments
 (0)