From 4c8af3b9fdcdb2939b4263d73d3ce0a34c2fef3d Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 13 Mar 2020 15:48:53 +0100 Subject: [PATCH] Fix #76999: mb-regex-set-options return current options When setting new options, `mb_regex_set_options()` is supposed to return the *previous* options. --- ext/mbstring/php_mbregex.c | 8 +++++--- ext/mbstring/tests/bug76999.phpt | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 ext/mbstring/tests/bug76999.phpt diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index b6ed2b86e908e..1cd0fa3dec997 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -1691,8 +1691,8 @@ static void _php_mb_regex_set_options(OnigOptionType options, OnigSyntaxType *sy Set or get the default options for mbregex functions */ PHP_FUNCTION(mb_regex_set_options) { - OnigOptionType opt; - OnigSyntaxType *syntax; + OnigOptionType opt, prev_opt; + OnigSyntaxType *syntax, *prev_syntax; char *string = NULL; size_t string_len; char buf[16]; @@ -1705,7 +1705,9 @@ PHP_FUNCTION(mb_regex_set_options) opt = 0; syntax = NULL; _php_mb_regex_init_options(string, string_len, &opt, &syntax, NULL); - _php_mb_regex_set_options(opt, syntax, NULL, NULL); + _php_mb_regex_set_options(opt, syntax, &prev_opt, &prev_syntax); + opt = prev_opt; + syntax = prev_syntax; } else { opt = MBREX(regex_default_options); syntax = MBREX(regex_default_syntax); diff --git a/ext/mbstring/tests/bug76999.phpt b/ext/mbstring/tests/bug76999.phpt new file mode 100644 index 0000000000000..830dd9a1297c9 --- /dev/null +++ b/ext/mbstring/tests/bug76999.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #76999 (mb-regex-set-options return current options) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(2) "pr" +string(2) "mr" +string(3) "imd" +string(2) "mr" +string(1) "r"