]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0278: viminfo: heap buffer overflow when reading viminfo file v9.2.0278
authorChristian Brabandt <cb@256bit.org>
Wed, 1 Apr 2026 15:03:58 +0000 (15:03 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 1 Apr 2026 15:06:21 +0000 (15:06 +0000)
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>
src/testdir/test_viminfo.vim
src/version.c
src/viminfo.c

index ff79265f8e0717ae6f51f84443dacce3bb808c64..b3a8b91cb1d0b244aa36202e5080fb2964be2d16 100644 (file)
@@ -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
index 075253bfd72c60c3d6c15351a4c670bc2580a11f..009c33276162d402ac326d7381374adbe115e33d 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    278,
 /**/
     277,
 /**/
index 9b60ec59457b4a4208ea210b97fd6d41e025c224..8b6aa3e70a0c5a6c9c3529e35027c106969eb16c 100644 (file)
@@ -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;