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:
committed by
Bram Moolenaar
parent
5d9826973d
commit
f5d639a8af
@@ -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 < buf + readlen || (readlen <= 0 && (prevlen > 0 || binary));
|
||||||
++p)
|
++p)
|
||||||
{
|
{
|
||||||
if (*p == '\n' || readlen <= 0)
|
if (readlen <= 0 || *p == '\n')
|
||||||
{
|
{
|
||||||
listitem_T *li;
|
listitem_T *li;
|
||||||
char_u *s = NULL;
|
char_u *s = NULL;
|
||||||
|
@@ -93,6 +93,13 @@ func Test_readfile_binary()
|
|||||||
call delete('XReadfile_bin')
|
call delete('XReadfile_bin')
|
||||||
endfunc
|
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()
|
func Test_readfile_bom()
|
||||||
call writefile(["\ufeffFOO", "FOO\ufeffBAR"], 'XReadfile_bom')
|
call writefile(["\ufeffFOO", "FOO\ufeffBAR"], 'XReadfile_bom')
|
||||||
call assert_equal(['FOO', 'FOOBAR'], readfile('XReadfile_bom'))
|
call assert_equal(['FOO', 'FOOBAR'], readfile('XReadfile_bom'))
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4070,
|
||||||
/**/
|
/**/
|
||||||
4069,
|
4069,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user