Skip to content

Commit 7bf1f9d

Browse files
cmb69smalyshev
authored andcommitted
Fix #75457: heap-use-after-free in php7.0.25
Backport <https://vcs.pcre.org/pcre?view=revision&revision=1638>.
1 parent 1258303 commit 7bf1f9d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ext/pcre/pcrelib/pcre_compile.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ static const char error_texts[] =
483483
"lookbehind assertion is not fixed length\0"
484484
"malformed number or name after (?(\0"
485485
"conditional group contains more than two branches\0"
486-
"assertion expected after (?(\0"
486+
"assertion expected after (?( or (?(?C)\0"
487487
"(?R or (?[+-]digits must be followed by )\0"
488488
/* 30 */
489489
"unknown POSIX class name\0"
@@ -6732,6 +6732,15 @@ for (;; ptr++)
67326732
for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;
67336733
if (ptr[i] == CHAR_RIGHT_PARENTHESIS)
67346734
tempptr += i + 1;
6735+
6736+
/* tempptr should now be pointing to the opening parenthesis of the
6737+
assertion condition. */
6738+
6739+
if (*tempptr != CHAR_LEFT_PARENTHESIS)
6740+
{
6741+
*errorcodeptr = ERR28;
6742+
goto FAILED;
6743+
}
67356744
}
67366745

67376746
/* For conditions that are assertions, check the syntax, and then exit

ext/pcre/tests/bug75457.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #75457 (heap-use-after-free in php7.0.25)
3+
--FILE--
4+
<?php
5+
$pattern = "/(((?(?C)0?=))(?!()0|.(?0)0)())/";
6+
var_dump(preg_match($pattern, "hello"));
7+
?>
8+
--EXPECTF--
9+
Warning: preg_match(): Compilation failed: assertion expected after (?( or (?(?C) at offset 4 in %sbug75457.php on line %d
10+
bool(false)

0 commit comments

Comments
 (0)