]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4065: computation overflow with large cound for :yank v8.2.4065
authorBram Moolenaar <Bram@vim.org>
Tue, 11 Jan 2022 19:34:16 +0000 (19:34 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 11 Jan 2022 19:34:16 +0000 (19:34 +0000)
Problem:    Computation overflow with large cound for :yank.
Solution:   Avoid an overflow.

src/ex_docmd.c
src/testdir/test_excmd.vim
src/version.c

index 71343590d0537a4a460f4136b310dd28fe85dca5..f16f6009fdbcc5abae3beb51f871834aa5d9e0ec 100644 (file)
@@ -2374,7 +2374,10 @@ do_one_cmd(
        else
        {
            ea.line1 = ea.line2;
-           ea.line2 += n - 1;
+           if (ea.line2 >= LONG_MAX - (n - 1))
+               ea.line2 = LONG_MAX;  // avoid overflow
+           else
+               ea.line2 += n - 1;
            ++ea.addr_count;
            /*
             * Be vi compatible: no error message for out of range.
index 6f648dd4e5c16d83ccf180b4dccfae752ffd6806..731e9aa94fbabe7b004ebf70340f32522a5fa1a7 100644 (file)
@@ -704,9 +704,14 @@ func Test_address_line_overflow()
     throw 'Skipped: only works with 64 bit long ints'
   endif
   new
-  call setline(1, 'text')
+  call setline(1, range(100))
   call assert_fails('|.44444444444444444444444', 'E1247:')
   call assert_fails('|.9223372036854775806', 'E1247:')
+
+  $
+  yank 77777777777777777777
+  call assert_equal("99\n", @")
+
   bwipe!
 endfunc
 
index 5f28da33d9c06f7c6c5f74e345c38f3f46099b78..e329775342f61258f38628c8b971361c1b69753a 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4065,
 /**/
     4064,
 /**/