vim-patch:9.0.0046: reading past end of completion with duplicate match

Problem:    Reading past end of completion with duplicate match.
Solution:   Check string length
baefde1455
This commit is contained in:
zeertzjq 2022-08-24 21:40:14 +08:00
parent c366a63e4c
commit 5d1f0c3eca
2 changed files with 11 additions and 1 deletions

View File

@ -709,7 +709,7 @@ static int ins_compl_add(char_u *const str, int len, char_u *const fname,
do { do {
if (!match_at_original_text(match) if (!match_at_original_text(match)
&& STRNCMP(match->cp_str, str, len) == 0 && STRNCMP(match->cp_str, str, len) == 0
&& match->cp_str[len] == NUL) { && ((int)STRLEN(match->cp_str) <= len || match->cp_str[len] == NUL)) {
FREE_CPTEXT(cptext, cptext_allocated); FREE_CPTEXT(cptext, cptext_allocated);
return NOTDONE; return NOTDONE;
} }

View File

@ -969,5 +969,15 @@ func Test_infercase_very_long_line()
set noic noinfercase set noic noinfercase
endfunc endfunc
func Test_ins_complete_add()
" this was reading past the end of allocated memory
new
norm o
norm 7o€€
sil! norm o
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab