Skip to content

Commit 7c7698f

Browse files
committed
Fix preg_replace_callback_array() pattern validation
Closes GH-11301
1 parent 4676d9b commit 7c7698f

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.8
44

5+
- PCRE:
6+
. Fix preg_replace_callback_array() pattern validation. (ilutov)
7+
58
- Standard:
69
. Fix access on NULL pointer in array_merge_recursive(). (ilutov)
710

ext/pcre/php_pcre.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,10 @@ PHP_FUNCTION(preg_replace_callback_array)
24252425
zend_argument_type_error(1, "must contain only valid callbacks");
24262426
goto error;
24272427
}
2428+
if (!str_idx_regex) {
2429+
zend_argument_type_error(1, "must contain only string patterns as keys");
2430+
goto error;
2431+
}
24282432

24292433
ZVAL_COPY_VALUE(&fci.function_name, replace);
24302434

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)