0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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)
This commit is contained in:
Dominique Pelle
2022-01-12 15:24:40 +00:00
committed by Bram Moolenaar
parent 5d9826973d
commit f5d639a8af
3 changed files with 10 additions and 1 deletions

View File

@@ -1796,7 +1796,7 @@ read_file_or_blob(typval_T *argvars, typval_T *rettv, int always_blob)
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;

View File

@@ -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'))

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4070,
/**/
4069,
/**/