]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.2107: [security]: FPE in adjust_plines_for_skipcol v9.0.2107
authorChristian Brabandt <cb@256bit.org>
Tue, 14 Nov 2023 19:05:59 +0000 (20:05 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 16 Nov 2023 21:04:37 +0000 (22:04 +0100)
Problem:  [security]: FPE in adjust_plines_for_skipcol
Solution: don't divide by zero, return zero

Prevent a floating point exception when calculating w_skipcol (which can
happen with a small window when the number option is set and cpo+=n).

Add a test to verify

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/move.c
src/testdir/test_scroll_opt.vim
src/version.c

index ce06dc3394689ea9e4e7e660b10d187381337813..fbb352a32e15af3b640fb036de033a2ed103adca 100644 (file)
@@ -45,8 +45,9 @@ adjust_plines_for_skipcol(win_T *wp)
        return 0;
 
     int width = wp->w_width - win_col_off(wp);
-    if (wp->w_skipcol >= width)
-       return (wp->w_skipcol - width) / (width + win_col_off2(wp)) + 1;
+    int w2 = width + win_col_off2(wp);
+    if (wp->w_skipcol >= width && w2 > 0)
+       return (wp->w_skipcol - width) / w2 + 1;
 
     return 0;
 }
index d5d08a24c20d4ba573a951c5cd45c6327ab76a48..342d382c20a5aab725fcf5107f9b4cc49d2bff7e 100644 (file)
@@ -926,4 +926,23 @@ func Test_smoothscroll_cursor_top()
   call StopVimInTerminal(buf)
 endfunc
 
+" Division by zero, shouldn't crash
+func Test_smoothscroll_crash()
+  CheckScreendump
+
+  let lines =<< trim END
+      20 new
+      vsp
+      put =repeat('aaaa', 20)
+      set nu fdc=1  smoothscroll cpo+=n
+      vert resize 0
+      exe "norm! 0\<c-e>"
+  END
+  call writefile(lines, 'XSmoothScrollCrash', 'D')
+  let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCrash', #{rows: 12, cols:40})
+  call term_sendkeys(buf, "2\<C-E>\<C-L>")
+
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index ec021985f25803e14b9bf5f30bf42ec116ee0a0a..684f3acf4c0f5af9e5c320e15d1941a1ea639fce 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2107,
 /**/
     2106,
 /**/