Skip to content

Commit 32968f8

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix preg_replace_callback_array() pattern validation
2 parents ded8b7f + 7c7698f commit 32968f8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ext/pcre/php_pcre.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,10 @@ PHP_FUNCTION(preg_replace_callback_array)
24062406
zend_argument_type_error(1, "must contain only valid callbacks");
24072407
goto error;
24082408
}
2409+
if (!str_idx_regex) {
2410+
zend_argument_type_error(1, "must contain only string patterns as keys");
2411+
goto error;
2412+
}
24092413

24102414
ZVAL_COPY_VALUE(&fci.function_name, replace);
24112415

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
preg_replace_callback_array() invalid pattern
3+
--FILE--
4+
<?php
5+
preg_replace_callback_array(
6+
[42 => function () {}],
7+
'a',
8+
);
9+
?>
10+
--EXPECTF--
11+
Fatal error: Uncaught TypeError: preg_replace_callback_array(): Argument #1 ($pattern) must contain only string patterns as keys in %s:%d
12+
Stack trace:
13+
#0 %s(%d): preg_replace_callback_array(Array, 'a')
14+
#1 {main}
15+
thrown in %s on line %d

0 commit comments

Comments
 (0)