Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect zval type_flags in preg_replace_callback_array() for immutable arrays #10970

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/pcre/php_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -2479,7 +2479,11 @@ PHP_FUNCTION(preg_replace_callback_array)
}

if (subject_ht) {
RETURN_ARR(subject_ht);
RETVAL_ARR(subject_ht);
if (GC_FLAGS(subject_ht) & GC_IMMUTABLE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (GC_FLAGS(subject_ht) & GC_IMMUTABLE) {
if (GC_FLAGS(subject_ht) & IS_ARRAY_IMMUTABLE) {

Maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I forgot we have an alias. Thanks!

Z_TYPE_FLAGS_P(return_value) = 0;
}
return;
} else {
RETURN_STR(subject_str);
}
Expand Down
11 changes: 11 additions & 0 deletions ext/pcre/tests/gh10968.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
GH-10968: preg_replace_callback_array() segmentation fault
--FILE--
<?php
var_dump(preg_replace_callback_array([], []));
var_dump(preg_replace_callback_array([], ''));
?>
--EXPECT--
array(0) {
}
string(0) ""