Mercurial > vim
changeset 27082:360a6a1ca9dd v8.2.4070
patch 8.2.4070: using uninitialized memory when reading empty file
Commit: https://github.com/vim/vim/commit/f5d639a8af719eb8ecb141b5c0890627e4d83134
Author: Dominique Pelle <dominique.pelle@gmail.com>
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 12 Jan 2022 16:30:07 +0100 |
parents | fbd98e593843 |
children | 15f9359846ad |
files | src/filepath.c src/testdir/test_eval_stuff.vim src/version.c |
diffstat | 3 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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'))