From 807934d08345c69ae31e0a0a1fcf7c92431d6204 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 18 Nov 2014 13:07:37 +0400 Subject: [PATCH] MDEV-7086 main.ctype_cp932 fails in buildbot on a valgrind build Removing a redundant and wrong condition which could access beyond the pattern string range. --- strings/ctype-bin.c | 2 +- strings/ctype-mb.c | 4 ++-- strings/ctype-simple.c | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c index 3ca4ba2b430..2e699db0bd3 100644 --- a/strings/ctype-bin.c +++ b/strings/ctype-bin.c @@ -395,7 +395,7 @@ int my_wildcmp_bin_impl(CHARSET_INFO *cs, if (tmp <= 0) return(tmp); } - } while (str != str_end && wildstr[0] != w_many); + } while (str != str_end); return(-1); } } diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c index b0413099ca8..02a9a91ca6a 100644 --- a/strings/ctype-mb.c +++ b/strings/ctype-mb.c @@ -354,7 +354,7 @@ int my_wildcmp_mb_impl(CHARSET_INFO *cs, if (tmp <= 0) return (tmp); } - } while (str != str_end && wildstr[0] != w_many); + } while (str != str_end); return(-1); } } @@ -1192,7 +1192,7 @@ static int my_wildcmp_mb_bin_impl(CHARSET_INFO *cs, if (tmp <= 0) return (tmp); } - } while (str != str_end && wildstr[0] != w_many); + } while (str != str_end); return(-1); } } diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index 0785ba35700..7f13cef4474 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -936,9 +936,14 @@ int my_wildcmp_8bit_impl(CHARSET_INFO *cs, cmp=likeconv(cs,cmp); do { + /* + Find the next character in the subject string equal to 'cmp', then + check recursively my_wildcmp_8bit_impl() for the pattern remainder. + */ while (str != str_end && (uchar) likeconv(cs,*str) != cmp) str++; - if (str++ == str_end) return(-1); + if (str++ == str_end) + return(-1); /* 'cmp' was not found in the subject string */ { int tmp=my_wildcmp_8bit_impl(cs,str,str_end, wildstr,wildend,escape,w_one, @@ -946,7 +951,13 @@ int my_wildcmp_8bit_impl(CHARSET_INFO *cs, if (tmp <= 0) return(tmp); } - } while (str != str_end && wildstr[0] != w_many); + /* + The recursion call did not match. But it returned 1, which means + the pattern remainder has some non-special characters. + Continue, there is a chance that we'll find another 'cmp' + at a different position in the subject string. + */ + } while (str != str_end); return(-1); } }