From 99645e5be59145bcab2fe36aefde4224e6e69961 Mon Sep 17 00:00:00 2001 From: Neeraj Bisht Date: Mon, 14 Jan 2013 14:59:48 +0530 Subject: BUG#14303860 - EXECUTING A SELECT QUERY WITH TOO MANY WILDCARDS CAUSES A SEGFAULT Back port from 5.6 and trunk --- strings/ctype-mb.c | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'strings/ctype-mb.c') diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c index 76dae6762af..92d7b5f48c8 100644 --- a/strings/ctype-mb.c +++ b/strings/ctype-mb.c @@ -148,13 +148,16 @@ int my_strcasecmp_mb(CHARSET_INFO * cs,const char *s, const char *t) #define likeconv(s,A) (uchar) (s)->sort_order[(uchar) (A)] -int my_wildcmp_mb(CHARSET_INFO *cs, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many) +static +int my_wildcmp_mb_impl(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, int recurse_level) { int result= -1; /* Not found, using wildcards */ + if (my_string_stack_guard && my_string_stack_guard(recurse_level)) + return 1; while (wildstr != wildend) { while (*wildstr != w_many && *wildstr != w_one) @@ -243,8 +246,8 @@ int my_wildcmp_mb(CHARSET_INFO *cs, INC_PTR(cs,str, str_end); } { - int tmp=my_wildcmp_mb(cs,str,str_end,wildstr,wildend,escape,w_one, - w_many); + int tmp=my_wildcmp_mb_impl(cs,str,str_end,wildstr,wildend,escape,w_one, + w_many, recurse_level + 1); if (tmp <= 0) return (tmp); } @@ -255,6 +258,16 @@ int my_wildcmp_mb(CHARSET_INFO *cs, return (str != str_end ? 1 : 0); } +int my_wildcmp_mb(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many) +{ + return my_wildcmp_mb_impl(cs, str, str_end, + wildstr, wildend, + escape, w_one, w_many, 1); +} + size_t my_numchars_mb(CHARSET_INFO *cs __attribute__((unused)), const char *pos, const char *end) @@ -697,13 +710,15 @@ fill_max_and_min: } -static int my_wildcmp_mb_bin(CHARSET_INFO *cs, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many) +static int my_wildcmp_mb_bin_impl(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, int recurse_level) { int result= -1; /* Not found, using wildcards */ + if (my_string_stack_guard && my_string_stack_guard(recurse_level)) + return 1; while (wildstr != wildend) { while (*wildstr != w_many && *wildstr != w_one) @@ -790,7 +805,9 @@ static int my_wildcmp_mb_bin(CHARSET_INFO *cs, INC_PTR(cs,str, str_end); } { - int tmp=my_wildcmp_mb_bin(cs,str,str_end,wildstr,wildend,escape,w_one,w_many); + int tmp=my_wildcmp_mb_bin_impl(cs,str,str_end, + wildstr,wildend,escape, + w_one,w_many, recurse_level+1); if (tmp <= 0) return (tmp); } @@ -801,6 +818,17 @@ static int my_wildcmp_mb_bin(CHARSET_INFO *cs, return (str != str_end ? 1 : 0); } +int +my_wildcmp_mb_bin(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many) +{ + return my_wildcmp_mb_bin_impl(cs, str, str_end, + wildstr, wildend, + escape, w_one, w_many, 1); +} + /* Data was produced from EastAsianWidth.txt -- cgit v1.2.1