1
0
forked from aniani/vim

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.
This commit is contained in:
Bram Moolenaar
2022-07-29 16:22:25 +01:00
parent 1e56bda904
commit f50940531d
3 changed files with 22 additions and 1 deletions

View File

@@ -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)