com php-src: Fix #78853: preg_match() may return in teger > 1: NEWS ext/pcre/php_pcre.c ext/pcr e/tests/bug78853.phpt

From: Date: Fri, 22 Nov 2019 18:26:26 +0000
Subject: com php-src: Fix #78853: preg_match() may return in teger > 1: NEWS ext/pcre/php_pcre.c ext/pcr e/tests/bug78853.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-109309@lists.php.net to get a copy of this message
Commit: e1da72bdf18aa3d413c5324bccfd8dc521c217e3 Author: Christoph M. Becker <cmbecker69@gmx.de> Fri, 22 Nov 2019 19:21:43 +0100 Parents: e981f5af51bf2a16965aad68ae268021dc251c9c Branches: PHP-7.3 PHP-7..4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e1da72bdf18aa3d413c5324bccfd8dc521c217e3 Log: 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> Bugs: https://bugs.php.net/78853 Changed paths: M NEWS M ext/pcre/php_pcre.c A ext/pcre/tests/bug78853.phpt Diff: diff --git a/NEWS b/NEWS index abedf9c09e2..53ad0a7a4d0 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,9 @@ PHP NEWS . Fixed $x = (bool)$x; with opcache (should emit undeclared variable notice). (Tyson Andre) +- PCRE: + . Fixed bug #78853 (preg_match() may return integer > 1). (cmb) + - Standard: . Fixed bug #78759 (array_search in $GLOBALS). (Nikita) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 882389e1cef..38eabe2556d 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1344,7 +1344,11 @@ matched: count = pcre2_match(pce->re, (PCRE2_SPTR)subject, subject_len, start_offset2, PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED, match_data, mctx); if (count >= 0) { - goto matched; + if (global) { + goto matched; + } else { + break; + } } else if (count == PCRE2_ERROR_NOMATCH) { /* If we previously set PCRE2_NOTEMPTY_ATSTART after a null match, this is not necessarily the end. We need to advance diff --git a/ext/pcre/tests/bug78853.phpt b/ext/pcre/tests/bug78853.phpt new file mode 100644 index 00000000000..369ed0f9260 --- /dev/null +++ b/ext/pcre/tests/bug78853.phpt @@ -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)

« previous php.cvs (#109309) next »