1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.5'

* PHP-8.5:
  ext/pcre: preg_match() fix memory leak with invalid regexes.
This commit is contained in:
David Carlier
2026-02-24 22:20:15 +00:00
2 changed files with 28 additions and 1 deletions

View File

@@ -1481,7 +1481,8 @@ ZEND_FRAMELESS_FUNCTION(preg_match, 2)
/* Compile regex or get it from cache. */
pcre_cache_entry *pce;
if ((pce = pcre_get_compiled_regex_cache(regex)) == NULL) {
RETURN_FALSE;
RETVAL_FALSE;
goto flf_clean;
}
pce->refcount++;

View File

@@ -0,0 +1,26 @@
--TEST--
Memory leak in preg_match() frameless function with invalid regex and object arguments
--FILE--
<?php
class Str {
private $val;
public function __construct($val) {
$this->val = $val;
}
public function __toString() {
return $this->val;
}
}
$regex = new Str("invalid regex");
$subject = new Str("some subject");
// Running in a loop to ensure leak detection if run with memory tools
for ($i = 0; $i < 100; $i++) {
@preg_match($regex, $subject);
}
echo "Done";
?>
--EXPECT--
Done