]> granicus.if.org Git - vim/commitdiff
patch 8.2.2422: crash when deleting with line number out of range v8.2.2422
authorBram Moolenaar <Bram@vim.org>
Thu, 28 Jan 2021 16:24:58 +0000 (17:24 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 28 Jan 2021 16:24:58 +0000 (17:24 +0100)
Problem:    Crash when deleting with line number out of range. (Houyunsong)
Solution:   Avoid using a negative line number.

src/normal.c
src/testdir/test_ex_mode.vim
src/version.c

index c70971f8e98fee6cac79b7f1b8c8d777c23d1476..9fbfadfbc71450841667cd0ff9d30f8c0cbd8a5c 100644 (file)
@@ -630,7 +630,7 @@ getcount:
            }
            else
                ca.count0 = ca.count0 * 10 + (c - '0');
-           if (ca.count0 < 0)      // got too large!
+           if (ca.count0 < 0)      // overflow
                ca.count0 = 999999999L;
 #ifdef FEAT_EVAL
            // Set v:count here, when called from main() and not a stuffed
@@ -701,6 +701,8 @@ getcount:
            ca.count0 *= ca.opcount;
        else
            ca.count0 = ca.opcount;
+       if (ca.count0 < 0)          // overflow
+           ca.count0 = 999999999L;
     }
 
     /*
@@ -4775,6 +4777,8 @@ nv_percent(cmdarg_T *cap)
            else
                curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count *
                                                    cap->count0 + 99L) / 100L;
+           if (curwin->w_cursor.lnum < 1)
+               curwin->w_cursor.lnum = 1;
            if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
                curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
            beginline(BL_SOL | BL_FIX);
index 3c6d08efb826ecf403304f900d2066924ad0fb91..a07649e0b82d989d88c5dfefc07705ecf45671ec 100644 (file)
@@ -206,4 +206,20 @@ func Test_ex_mode_with_global()
   call delete('Xexmodescript')
 endfunc
 
+func Test_ex_mode_count_overflow()
+  " this used to cause a crash
+  let lines =<< trim END
+    call feedkeys("\<Esc>Q\<CR>")
+    v9|9silent! vi|333333233333y32333333%O
+    call writefile(['done'], 'Xdidexmode')
+    qall!
+  END
+  call writefile(lines, 'Xexmodescript')
+  call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript -c qa'))
+  call assert_equal(['done'], readfile('Xdidexmode'))
+
+  call delete('Xdidexmode')
+  call delete('Xexmodescript')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 9709e3278652e10426122f6124a4c7a0e57ecb4f..c710be863c5364e6b7bdfa9565209c8ddf4ed29d 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2422,
 /**/
     2421,
 /**/