From b1fc1fb9376f22693b610961a097f6d0ff6dc484 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 15 Oct 2016 23:03:03 +0200 Subject: [PATCH] Normalize preg_replace_callback() return value One particular error case was returning the argument without casting to string. --- ext/pcre/php_pcre.c | 2 +- ext/pcre/tests/preg_replace_callback3.phpt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index ef9569b860..53e122c82b 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1584,7 +1584,7 @@ static PHP_FUNCTION(preg_replace_callback) if (!zend_is_callable(replace, 0, &callback_name)) { php_error_docref(NULL, E_WARNING, "Requires argument 2, '%s', to be a valid callback", ZSTR_VAL(callback_name)); zend_string_release(callback_name); - ZVAL_COPY(return_value, subject); + ZVAL_STR(return_value, zval_get_string(subject)); return; } zend_string_release(callback_name); diff --git a/ext/pcre/tests/preg_replace_callback3.phpt b/ext/pcre/tests/preg_replace_callback3.phpt index 6484c074fe..fc3218b9e7 100644 --- a/ext/pcre/tests/preg_replace_callback3.phpt +++ b/ext/pcre/tests/preg_replace_callback3.phpt @@ -28,13 +28,13 @@ Warning: preg_replace_callback() expects at least 3 parameters, 2 given in %s on NULL Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d -int(3) +string(1) "3" Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d -int(3) +string(1) "3" Warning: preg_replace_callback(): Requires argument 2, '2', to be a valid callback in %s on line %d -int(3) +string(1) "3" Warning: preg_replace_callback() expects parameter 4 to be integer, string given in %s on line %d NULL -- 2.50.1