Skip to content

Commit 955f82f

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/pcre: preg_match() fix memory leak with invalid regexes.
2 parents 022793e + 6c45f7a commit 955f82f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/pcre/php_pcre.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,8 @@ ZEND_FRAMELESS_FUNCTION(preg_match, 2)
14811481
/* Compile regex or get it from cache. */
14821482
pcre_cache_entry *pce;
14831483
if ((pce = pcre_get_compiled_regex_cache(regex)) == NULL) {
1484-
RETURN_FALSE;
1484+
RETVAL_FALSE;
1485+
goto flf_clean;
14851486
}
14861487

14871488
pce->refcount++;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Memory leak in preg_match() frameless function with invalid regex and object arguments
3+
--FILE--
4+
<?php
5+
class Str {
6+
private $val;
7+
public function __construct($val) {
8+
$this->val = $val;
9+
}
10+
public function __toString() {
11+
return $this->val;
12+
}
13+
}
14+
15+
$regex = new Str("invalid regex");
16+
$subject = new Str("some subject");
17+
18+
// Running in a loop to ensure leak detection if run with memory tools
19+
for ($i = 0; $i < 100; $i++) {
20+
@preg_match($regex, $subject);
21+
}
22+
23+
echo "Done";
24+
?>
25+
--EXPECT--
26+
Done

0 commit comments

Comments
 (0)