Skip to content

Commit 9dcaa85

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: ext/pcre: preg_match() use-after-free of the subpatterns table across requests.
2 parents eb697f1 + d831241 commit 9dcaa85

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎ext/pcre/php_pcre.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static PHP_RINIT_FUNCTION(pcre)
469469
}
470470
/* }}} */
471471

472-
static PHP_RSHUTDOWN_FUNCTION(pcre)
472+
static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(pcre)
473473
{
474474
pcre_cache_entry *pce;
475475
ZEND_HASH_MAP_FOREACH_PTR(&PCRE_G(pcre_cache), pce) {
@@ -479,6 +479,11 @@ static PHP_RSHUTDOWN_FUNCTION(pcre)
479479
}
480480
} ZEND_HASH_FOREACH_END();
481481

482+
return SUCCESS;
483+
}
484+
485+
static PHP_RSHUTDOWN_FUNCTION(pcre)
486+
{
482487
pcre2_general_context_free(PCRE_G(gctx_zmm));
483488
PCRE_G(gctx_zmm) = NULL;
484489

@@ -3166,7 +3171,7 @@ zend_module_entry pcre_module_entry = {
31663171
PHP_MODULE_GLOBALS(pcre),
31673172
PHP_GINIT(pcre),
31683173
PHP_GSHUTDOWN(pcre),
3169-
NULL,
3174+
ZEND_MODULE_POST_ZEND_DEACTIVATE_N(pcre),
31703175
STANDARD_MODULE_PROPERTIES_EX
31713176
};
31723177

‎ext/pcre/tests/gh26100.phpt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-26100 (Named subpatterns table created after the pcre request shutdown)
3+
--CREDITS--
4+
br1p4v3s1
5+
--FILE--
6+
<?php
7+
class W {
8+
public $context;
9+
function stream_open($path, $mode, $options, &$opened_path) { return true; }
10+
function stream_close() {
11+
preg_match('/(?<n>a)?b/', 'ab', $m);
12+
var_dump($m['n']);
13+
echo preg_replace_callback('/(?<o>b)/', fn($m) => '[' . $m['o'] . ']', 'abb'), PHP_EOL;
14+
}
15+
}
16+
stream_wrapper_register('foo', 'W');
17+
$h = fopen('foo://bar', 'r');
18+
echo 'done', PHP_EOL;
19+
?>
20+
--EXPECT--
21+
done
22+
string(1) "a"
23+
a[b][b]

0 commit comments

Comments
 (0)