summaryrefslogtreecommitdiff
path: root/ext/mbstring/mbstring.c
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2019-04-01 00:32:49 -0700
committerStanislav Malyshev <stas@php.net>2019-04-01 00:32:49 -0700
commit63e0c220374733947ed869597ecf81ea2de138b2 (patch)
treeb0fa5adf57f3cf377dc9020a56f2bc9376a8fee4 /ext/mbstring/mbstring.c
parent9a06876072b9ccb023d4a14426ccb587f10882f3 (diff)
parent0eea9a642941ab5d4c612f8092f186977afbb73e (diff)
downloadphp-git-63e0c220374733947ed869597ecf81ea2de138b2.tar.gz
Merge branch 'PHP-7.4'
* PHP-7.4: Unfortunately, travis CI has old oniguruma library Update NEWS & UPGRADING Add fallbacks for older oniguruma versions Add mbstring.regex_stack_limit to php.ini-* Implement RF bug #72777 - ensure stack limits on mbstring functions.
Diffstat (limited to 'ext/mbstring/mbstring.c')
-rw-r--r--ext/mbstring/mbstring.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index fce4dc5207..3cd6449c43 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -60,6 +60,17 @@
# include "php_onig_compat.h"
# include <oniguruma.h>
# undef UChar
+#if ONIGURUMA_VERSION_INT < 60800
+typedef void OnigMatchParam;
+#define onig_new_match_param() (NULL)
+#define onig_initialize_match_param(x)
+#define onig_set_match_stack_limit_size_of_match_param(x, y)
+#define onig_free_match_param(x)
+#define onig_search_with_param(reg, str, end, start, range, region, option, mp) \
+onig_search(reg, str, end, start, range, region, option)
+#define onig_match_with_param(re, str, end, at, region, option, mp) \
+onig_match(re, str, end, at, region, option)
+#endif
#else
# include "ext/pcre/php_pcre.h"
#endif
@@ -1012,9 +1023,18 @@ static void *_php_mb_compile_regex(const char *pattern)
/* {{{ _php_mb_match_regex */
static int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
{
- return onig_search((php_mb_regex_t *)opaque, (const OnigUChar *)str,
- (const OnigUChar*)str + str_len, (const OnigUChar *)str,
- (const OnigUChar*)str + str_len, NULL, ONIG_OPTION_NONE) >= 0;
+ OnigMatchParam *mp = onig_new_match_param();
+ int err;
+ onig_initialize_match_param(mp);
+ if (!ZEND_LONG_UINT_OVFL(MBSTRG(regex_stack_limit))) {
+ onig_set_match_stack_limit_size_of_match_param(mp, (unsigned int)MBSTRG(regex_stack_limit));
+ }
+ /* search */
+ err = onig_search_with_param((php_mb_regex_t *)opaque, (const OnigUChar *)str,
+ (const OnigUChar*)str + str_len, (const OnigUChar *)str,
+ (const OnigUChar*)str + str_len, NULL, ONIG_OPTION_NONE, mp);
+ onig_free_match_param(mp);
+ return err >= 0;
}
/* }}} */
@@ -1485,6 +1505,9 @@ PHP_INI_BEGIN()
PHP_INI_ALL,
OnUpdateBool,
strict_detection, zend_mbstring_globals, mbstring_globals)
+#if HAVE_MBREGEX
+ STD_PHP_INI_ENTRY("mbstring.regex_stack_limit", "100000",PHP_INI_ALL, OnUpdateLong, regex_stack_limit, zend_mbstring_globals, mbstring_globals)
+#endif
PHP_INI_END()
/* }}} */