vim-patch:8.2.4974: ":so" command may read after end of buffer

Problem:    ":so" command may read after end of buffer.
Solution:   Compute length of text properly.

4748c4bd64

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2024-04-24 19:54:02 +08:00
parent 6063975bcf
commit e59f31e6c5
2 changed files with 13 additions and 1 deletions

View File

@ -2628,6 +2628,7 @@ static char *get_one_sourceline(source_cookie_T *sp)
ga_grow(&ga, 1);
buf = (char *)ga.ga_data;
buf[ga.ga_len++] = NUL;
len = ga.ga_len;
} else {
buf = ga.ga_data;
retry:
@ -2638,8 +2639,8 @@ retry:
}
break;
}
len = ga.ga_len + (int)strlen(buf + ga.ga_len);
}
len = ga.ga_len + (int)strlen(buf + ga.ga_len);
#ifdef USE_CRNL
// Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the
// CTRL-Z by its own, or after a NL.

View File

@ -612,6 +612,17 @@ func Test_source_buffer_long_line()
norm300gr0
so
bwipe!
let lines =<< trim END
new
norm 10a0000000000ø00000000000
norm i0000000000000000000
silent! so
END
call writefile(lines, 'Xtest.vim')
source Xtest.vim
bwipe!
call delete('Xtest.vim')
endfunc