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.

f50940531d

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2024-07-31 06:37:58 +08:00
parent 63cd2adf3d
commit 17f95fe79b
2 changed files with 18 additions and 1 deletions

View File

@@ -1804,7 +1804,9 @@ static inline char *cstrchr(const char *const s, const int c)
if (c > 0x80) {
const int folded_c = utf_fold(c);
for (const char *p = s; *p != NUL; p += utfc_ptr2len(p)) {
if (utf_fold(utf_ptr2char(p)) == folded_c) {
const int uc = utf_ptr2char(p);
// Do not match an illegal byte. E.g. 0xff matches 0xc3 0xbf, not 0xff.
if ((uc < 0x80 || uc != (uint8_t)(*p)) && utf_fold(uc) == folded_c) {
return (char *)p;
}
}