From 6952b1951b6a60df8d477279f4451094fb51c413 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Nov 2023 08:40:02 +0800 Subject: vim-patch:9.0.2107: [security]: FPE in adjust_plines_for_skipcol (#26082) 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 https://github.com/vim/vim/commit/cb0b99f0672d8446585d26e998343dceca17d1ce Co-authored-by: Christian Brabandt --- test/functional/legacy/scroll_opt_spec.lua | 16 ++++++++++++++++ test/old/testdir/test_scroll_opt.vim | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'test') diff --git a/test/functional/legacy/scroll_opt_spec.lua b/test/functional/legacy/scroll_opt_spec.lua index d4e4702f5e..8ac1141c2b 100644 --- a/test/functional/legacy/scroll_opt_spec.lua +++ b/test/functional/legacy/scroll_opt_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local exec = helpers.exec local feed = helpers.feed +local assert_alive = helpers.assert_alive before_each(clear) @@ -1007,6 +1008,21 @@ describe('smoothscroll', function() ]]) end) + -- oldtest: Test_smoothscroll_crash() + it('does not crash with small window and cpo+=n', function() + screen:try_resize(40, 12) + exec([[ + 20 new + vsp + put =repeat('aaaa', 20) + set nu fdc=1 smoothscroll cpo+=n + vert resize 0 + exe "norm! 0\" + ]]) + feed('2') + assert_alive() + end) + it("works with virt_lines above and below", function() screen:try_resize(55, 7) exec([=[ diff --git a/test/old/testdir/test_scroll_opt.vim b/test/old/testdir/test_scroll_opt.vim index f428e77579..f2e7bc6b56 100644 --- a/test/old/testdir/test_scroll_opt.vim +++ b/test/old/testdir/test_scroll_opt.vim @@ -929,4 +929,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\" + END + call writefile(lines, 'XSmoothScrollCrash', 'D') + let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCrash', #{rows: 12, cols:40}) + call term_sendkeys(buf, "2\\") + + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit