From e6cfd20b7fdeea2478c444e6f9b60c1e18ccdf00 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Feb 2022 20:03:02 +0800 Subject: vim-patch:8.2.4298: divide by zero with huge tabstop value Problem: Divide by zero with huge tabstop value. Solution: Reject tabstop value that overflows to zero. https://github.com/vim/vim/commit/fc88df42f1ae64bcc4d6cbc0fbd3445f8c59afdf --- src/nvim/option.c | 2 +- src/nvim/testdir/test_vartabs.vim | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/option.c b/src/nvim/option.c index 2c4c4819ea..b9fed8b378 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -7551,7 +7551,7 @@ bool tabstop_set(char_u *var, long **array) int n = atoi((char *)cp); // Catch negative values, overflow and ridiculous big values. - if (n < 0 || n > TABSTOP_MAX) { + if (n <= 0 || n > TABSTOP_MAX) { semsg(_(e_invarg2), cp); XFREE_CLEAR(*array); return false; diff --git a/src/nvim/testdir/test_vartabs.vim b/src/nvim/testdir/test_vartabs.vim index 46e0d62313..d05008d2dd 100644 --- a/src/nvim/testdir/test_vartabs.vim +++ b/src/nvim/testdir/test_vartabs.vim @@ -135,6 +135,16 @@ func Test_vartabs() bwipeout! endfunc +func Test_retab_invalid_arg() + new + call setline(1, "\ttext") + retab 0 + call assert_fails("retab -8", 'E487: Argument must be positive') + call assert_fails("retab 10000", 'E475:') + call assert_fails("retab 720575940379279360", 'E475:') + bwipe! +endfunc + func! Test_vartabs_breakindent() if !exists("+breakindent") return -- cgit