diff src/regexp.c @ 29527:e7158d889784 v9.0.0105

patch 9.0.0105: illegal memory access when pattern starts with illegal byte Commit: https://github.com/vim/vim/commit/f50940531dd57135fe60aa393ac9d3281f352d88 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 29 16:22:25 2022 +0100 patch 9.0.0105: illegal memory access when pattern starts with illegal byte Problem: Illegal memory access when pattern starts with illegal byte. Solution: Do not match a character with an illegal byte.
author Bram Moolenaar <Bram@vim.org>
date Fri, 29 Jul 2022 17:30:03 +0200
parents 057c26b5c33a
children a63d3a0e9aba
line wrap: on
line diff
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -1641,7 +1641,11 @@ cstrchr(char_u *s, int c)
 	{
 	    if (enc_utf8 && c > 0x80)
 	    {
-		if (utf_fold(utf_ptr2char(p)) == cc)
+		int uc = utf_ptr2char(p);
+
+		// Do not match an illegal byte.  E.g. 0xff matches 0xc3 0xbf,
+		// not 0xff.
+		if ((uc < 0x80 || uc != *p) && utf_fold(uc) == cc)
 		    return p;
 	    }
 	    else if (*p == c || *p == cc)