From: Benno Schulenberg Date: Thu, 23 Jul 2015 19:18:25 +0000 (+0000) Subject: Finding only valid UTF-8 byte sequences when searching. X-Git-Tag: v2.5.0~146 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=b967368d413816e509967cca4983c333ef9c2e38;p=nano.git Finding only valid UTF-8 byte sequences when searching. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5316 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 092d2f68..bf6d70a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * doc/man/{nano.1,nanorc.5}, doc/texinfo/nano.texi: Add deprecation notices for the options 'set const', 'set poslog' and '--poslog'. Suggested by Eitan Adler. + * src/chars.c (mbstrcasestr, mbrevstrcasestr): When searching, find + only valid UTF-8 byte sequences. This fixes Savannah bug #45579. 2015-07-22 Mike Frysinger * src/files.c (check_dotnano), src/global.c (thanks_for_all_the_fish), diff --git a/src/chars.c b/src/chars.c index ccd9f33a..2f8de139 100644 --- a/src/chars.c +++ b/src/chars.c @@ -636,7 +636,8 @@ char *mbstrcasestr(const char *haystack, const char *needle) for (; *haystack != '\0' && haystack_len >= needle_len; haystack += move_mbright(haystack, 0), haystack_len--) { - if (mbstrncasecmp(haystack, needle, needle_len) == 0) + if (mbstrncasecmp(haystack, needle, needle_len) == 0 && + mblen(haystack, MB_CUR_MAX) > 0) return (char *)haystack; } @@ -729,8 +730,9 @@ char *mbrevstrcasestr(const char *haystack, const char *needle, const rev_start_len = mbstrlen(rev_start); while (!begin_line) { - if (rev_start_len >= needle_len && mbstrncasecmp(rev_start, - needle, needle_len) == 0) + if (rev_start_len >= needle_len && + mbstrncasecmp(rev_start, needle, needle_len) == 0 && + mblen(rev_start, MB_CUR_MAX) > 0) return (char *)rev_start; if (rev_start == haystack)