mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.4070: using uninitialized memory when reading empty file
Problem: Using uninitialized memory when reading empty file.
Solution: Check for empty file before checking for NL. (Dominique Pellé,
closes vim/vim#9511)
f5d639a8af
Co-authored-by: Dominique Pelle <dominique.pelle@gmail.com>
This commit is contained in:
parent
7765f2bb83
commit
b793395019
@ -5921,7 +5921,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
for (p = buf, start = buf;
|
||||
p < buf + readlen || (readlen <= 0 && (prevlen > 0 || binary));
|
||||
p++) {
|
||||
if (*p == '\n' || readlen <= 0) {
|
||||
if (readlen <= 0 || *p == '\n') {
|
||||
char *s = NULL;
|
||||
size_t len = (size_t)(p - start);
|
||||
|
||||
|
@ -120,6 +120,13 @@ func Test_readfile_binary()
|
||||
call delete('XReadfile_bin')
|
||||
endfunc
|
||||
|
||||
func Test_readfile_binary_empty()
|
||||
call writefile([], 'Xempty-file')
|
||||
" This used to compare uninitialized memory in Vim <= 8.2.4065
|
||||
call assert_equal([''], readfile('Xempty-file', 'b'))
|
||||
call delete('Xempty-file')
|
||||
endfunc
|
||||
|
||||
func Test_readfile_bom()
|
||||
call writefile(["\ufeffFOO", "FOO\ufeffBAR"], 'XReadfile_bom')
|
||||
call assert_equal(['FOO', 'FOOBAR'], readfile('XReadfile_bom'))
|
||||
|
Loading…
Reference in New Issue
Block a user