mirror of
https://github.com/vim/vim.git
synced 2026-05-28 00:21:37 +02:00
patch 9.2.0278: viminfo: heap buffer overflow when reading viminfo file
Problem: Reading a crafted viminfo file can cause a heap buffer
overflow because the length value from getdigits() is cast to
int, truncating large size_t values
Solution: Remove the (int) cast when calling alloc() (sentinel404)
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
@@ -1371,4 +1371,24 @@ func Test_viminfo_len_one()
|
||||
let &viminfofile = _viminfofile
|
||||
endfunc
|
||||
|
||||
func Test_viminfo_len_overflow()
|
||||
let _viminfofile = &viminfofile
|
||||
let &viminfofile=''
|
||||
let viminfo_file = tempname()
|
||||
defer delete(viminfo_file)
|
||||
|
||||
" Craft a viminfo entry with size_t length overflow
|
||||
call writefile(['# Viminfo',
|
||||
\ '|1,4', '|2,>4294967311',
|
||||
\ '|<"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||
\ '|<BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
|
||||
\ '|<CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC',
|
||||
\ '|<DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD'], viminfo_file, 'b')
|
||||
|
||||
" Should not crash or cause memory errors
|
||||
exe 'rviminfo! ' .. viminfo_file
|
||||
|
||||
let &viminfofile = _viminfofile
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
||||
@@ -734,6 +734,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
278,
|
||||
/**/
|
||||
277,
|
||||
/**/
|
||||
|
||||
+1
-1
@@ -1054,7 +1054,7 @@ barline_parse(vir_T *virp, char_u *text, garray_T *values)
|
||||
// Length includes the quotes.
|
||||
++p;
|
||||
len = getdigits(&p);
|
||||
buf = alloc((int)(len + 1));
|
||||
buf = alloc(len + 1);
|
||||
if (buf == NULL)
|
||||
return TRUE;
|
||||
p = buf;
|
||||
|
||||
Reference in New Issue
Block a user