Skip to content

Commit

Permalink
Fix #75457: heap-use-after-free in php7.0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
cmb69 authored and smalyshev committed Aug 26, 2019
1 parent 1258303 commit 7bf1f9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ext/pcre/pcrelib/pcre_compile.c
Expand Up @@ -483,7 +483,7 @@ static const char error_texts[] =
"lookbehind assertion is not fixed length\0"
"malformed number or name after (?(\0"
"conditional group contains more than two branches\0"
"assertion expected after (?(\0"
"assertion expected after (?( or (?(?C)\0"
"(?R or (?[+-]digits must be followed by )\0"
/* 30 */
"unknown POSIX class name\0"
Expand Down Expand Up @@ -6732,6 +6732,15 @@ for (;; ptr++)
for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;
if (ptr[i] == CHAR_RIGHT_PARENTHESIS)
tempptr += i + 1;

/* tempptr should now be pointing to the opening parenthesis of the
assertion condition. */

if (*tempptr != CHAR_LEFT_PARENTHESIS)
{
*errorcodeptr = ERR28;
goto FAILED;
}
}

/* For conditions that are assertions, check the syntax, and then exit
Expand Down
10 changes: 10 additions & 0 deletions ext/pcre/tests/bug75457.phpt
@@ -0,0 +1,10 @@
--TEST--
Bug #75457 (heap-use-after-free in php7.0.25)
--FILE--
<?php
$pattern = "/(((?(?C)0?=))(?!()0|.(?0)0)())/";
var_dump(preg_match($pattern, "hello"));
?>
--EXPECTF--
Warning: preg_match(): Compilation failed: assertion expected after (?( or (?(?C) at offset 4 in %sbug75457.php on line %d
bool(false)

0 comments on commit 7bf1f9d

Please sign in to comment.