# HG changeset patch # User Bram Moolenaar # Date 1642001407 -3600 # Node ID 360a6a1ca9dd0b10adb77a1f45fadfe2f4121e06 # Parent fbd98e5938432fcd73872def5fec0aeb3b96f1fe patch 8.2.4070: using uninitialized memory when reading empty file Commit: https://github.com/vim/vim/commit/f5d639a8af719eb8ecb141b5c0890627e4d83134 Author: Dominique Pelle Date: Wed Jan 12 15:24:40 2022 +0000 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 #9511) diff --git a/src/filepath.c b/src/filepath.c --- a/src/filepath.c +++ b/src/filepath.c @@ -1796,7 +1796,7 @@ read_file_or_blob(typval_T *argvars, typ p < buf + readlen || (readlen <= 0 && (prevlen > 0 || binary)); ++p) { - if (*p == '\n' || readlen <= 0) + if (readlen <= 0 || *p == '\n') { listitem_T *li; char_u *s = NULL; diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim --- a/src/testdir/test_eval_stuff.vim +++ b/src/testdir/test_eval_stuff.vim @@ -93,6 +93,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')) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4070, +/**/ 4069, /**/ 4068,