From af23d173883f47fd02a9a380c719e4428370b484 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 7 Mar 2023 04:13:04 +0100 Subject: test: move oldtests to test directory (#22536) The new oldtest directory is in test/old/testdir. The reason for this is that many tests have hardcoded the parent directory name to be 'testdir'. --- test/old/testdir/test_history.vim | 252 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 test/old/testdir/test_history.vim (limited to 'test/old/testdir/test_history.vim') diff --git a/test/old/testdir/test_history.vim b/test/old/testdir/test_history.vim new file mode 100644 index 0000000000..f1c31dee04 --- /dev/null +++ b/test/old/testdir/test_history.vim @@ -0,0 +1,252 @@ +" Tests for the history functions + +source check.vim +CheckFeature cmdline_hist + +set history=7 + +function History_Tests(hist) + " First clear the history + call histadd(a:hist, 'dummy') + call assert_true(histdel(a:hist)) + call assert_equal(-1, histnr(a:hist)) + call assert_equal('', histget(a:hist)) + + call assert_true('ls'->histadd(a:hist)) + call assert_true(histadd(a:hist, 'buffers')) + call assert_equal('buffers', histget(a:hist)) + call assert_equal('ls', histget(a:hist, -2)) + call assert_equal('ls', histget(a:hist, 1)) + call assert_equal('', histget(a:hist, 5)) + call assert_equal('', histget(a:hist, -5)) + call assert_equal(2, histnr(a:hist)) + call assert_true(histdel(a:hist, 2)) + call assert_false(a:hist->histdel(7)) + call assert_equal(1, histnr(a:hist)) + call assert_equal('ls', histget(a:hist, -1)) + + call assert_true(histadd(a:hist, 'buffers')) + call assert_true(histadd(a:hist, 'ls')) + call assert_equal('ls', a:hist->histget(-1)) + call assert_equal(4, a:hist->histnr()) + + let a=execute('history ' . a:hist) + call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a) + let a=execute('history all') + call assert_match("^\n # .* history\n 3 buffers\n> 4 ls", a) + + if len(a:hist) > 0 + let a=execute('history ' . a:hist . ' 2') + call assert_match("^\n # \\S* history$", a) + let a=execute('history ' . a:hist . ' 3') + call assert_match("^\n # \\S* history\n 3 buffers$", a) + let a=execute('history ' . a:hist . ' 4') + call assert_match("^\n # \\S* history\n> 4 ls$", a) + let a=execute('history ' . a:hist . ' 3,4') + call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a) + let a=execute('history ' . a:hist . ' -1') + call assert_match("^\n # \\S* history\n> 4 ls$", a) + let a=execute('history ' . a:hist . ' -2') + call assert_match("^\n # \\S* history\n 3 buffers$", a) + let a=execute('history ' . a:hist . ' -2,') + call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a) + let a=execute('history ' . a:hist . ' -3') + call assert_match("^\n # \\S* history$", a) + endif + + " Test for removing entries matching a pattern + for i in range(1, 3) + call histadd(a:hist, 'text_' . i) + endfor + call assert_true(histdel(a:hist, 'text_\d\+')) + call assert_equal('ls', histget(a:hist, -1)) + + " Test for freeing the entire history list + for i in range(1, 7) + call histadd(a:hist, 'text_' . i) + endfor + call histdel(a:hist) + for i in range(1, 7) + call assert_equal('', histget(a:hist, i)) + call assert_equal('', histget(a:hist, i - 7 - 1)) + endfor + + " Test for freeing an entry at the beginning of the history list + for i in range(1, 4) + call histadd(a:hist, 'text_' . i) + endfor + call histdel(a:hist, 1) + call assert_equal('', histget(a:hist, 1)) + call assert_equal('text_4', histget(a:hist, 4)) +endfunction + +function Test_History() + for h in ['cmd', ':', '', 'search', '/', '?', 'expr', '=', 'input', '@', 'debug', '>'] + call History_Tests(h) + endfor + + " Negative tests + call assert_false(histdel('abc')) + call assert_equal('', histget('abc')) + call assert_fails('call histdel([])', 'E730:') + call assert_equal('', histget(10)) + call assert_fails('call histget([])', 'E730:') + call assert_equal(-1, histnr('abc')) + call assert_fails('call histnr([])', 'E730:') + call assert_fails('history xyz', 'E488:') + call assert_fails('history ,abc', 'E488:') + call assert_fails('call histdel(":", "\\%(")', 'E53:') +endfunction + +function Test_history_truncates_long_entry() + " History entry short enough to fit on the screen should not be truncated. + call histadd(':', 'echo x' .. repeat('y', &columns - 17) .. 'z') + let a = execute('history : -1') + + call assert_match("^\n # cmd history\n" + \ .. "> *\\d\\+ echo x" .. repeat('y', &columns - 17) .. 'z$', a) + + " Long history entry should be truncated to fit on the screen, with, '...' + " inserted in the string to indicate the that there is truncation. + call histadd(':', 'echo x' .. repeat('y', &columns - 16) .. 'z') + let a = execute('history : -1') + call assert_match("^\n # cmd history\n" + \ .. "> *\\d\\+ echo xy\\+\.\.\.y\\+z$", a) +endfunction + +function Test_Search_history_window() + new + call setline(1, ['a', 'b', 'a', 'b']) + 1 + call feedkeys("/a\", 'xt') + call assert_equal('a', getline('.')) + 1 + call feedkeys("/b\", 'xt') + call assert_equal('b', getline('.')) + 1 + " select the previous /a command + call feedkeys("q/kk\", 'x!') + call assert_equal('a', getline('.')) + call assert_equal('a', @/) + bwipe! +endfunc + +" Test for :history command option completion +function Test_history_completion() + call feedkeys(":history \\\"\", 'tx') + call assert_equal('"history / : = > ? @ all cmd debug expr input search', @:) +endfunc + +" Test for increasing the 'history' option value +func Test_history_size() + let save_histsz = &history + set history=10 + call histadd(':', 'ls') + call histdel(':') + for i in range(1, 5) + call histadd(':', 'cmd' .. i) + endfor + call assert_equal(5, histnr(':')) + call assert_equal('cmd5', histget(':', -1)) + + set history=15 + for i in range(6, 10) + call histadd(':', 'cmd' .. i) + endfor + call assert_equal(10, histnr(':')) + call assert_equal('cmd1', histget(':', 1)) + call assert_equal('cmd10', histget(':', -1)) + + set history=5 + call histadd(':', 'abc') + call assert_equal('', histget(':', 6)) + call assert_equal('', histget(':', 12)) + call assert_equal('cmd7', histget(':', 7)) + call assert_equal('abc', histget(':', -1)) + + " This test works only when the language is English + if v:lang == "C" || v:lang =~ '^[Ee]n' + set history=0 + redir => v + call feedkeys(":history\", 'xt') + redir END + call assert_equal(["'history' option is zero"], split(v, "\n")) + endif + + let &history=save_histsz +endfunc + +" Test for recalling old search patterns in / +func Test_history_search() + call histdel('/') + let g:pat = [] + func SavePat() + call add(g:pat, getcmdline()) + return '' + endfunc + cnoremap eSavePat() + call histadd('/', 'pat1') + call histadd('/', 'pat2') + let @/ = '' + call feedkeys("/\\\\\\\\", 'xt') + call assert_equal(['pat2', 'pat1', ''], g:pat) + cunmap + delfunc SavePat + + " Search for a pattern that is not present in the history + call assert_beeps('call feedkeys("/a1b2\\", "xt")') + + " Recall patterns with 'history' set to 0 + set history=0 + let @/ = 'abc' + let cmd = 'call feedkeys("/\\\\\", "xt")' + call assert_fails(cmd, 'E486:') + set history& + + " Recall patterns till the end of history + set history=4 + call histadd('/', 'pat') + call histdel('/') + call histadd('/', 'pat1') + call histadd('/', 'pat2') + call assert_beeps('call feedkeys("/\\\\\", "xt")') + call assert_beeps('call feedkeys("/\", "xt")') + + " Test for wrapping around the history list + for i in range(3, 7) + call histadd('/', 'pat' .. i) + endfor + let upcmd = "\\\\\" + let downcmd = "\\\\\" + try + call feedkeys("/" .. upcmd .. "\", 'xt') + catch /E486:/ + endtry + call assert_equal('pat4', @/) + try + call feedkeys("/" .. upcmd .. downcmd .. "\", 'xt') + catch /E486:/ + endtry + call assert_equal('pat4', @/) + + " Test for changing the search command separator in the history + call assert_fails('call feedkeys("/def/\", "xt")', 'E486:') + call assert_fails('call feedkeys("?\\", "xt")', 'E486:') + call assert_equal('def?', histget('/', -1)) + + call assert_fails('call feedkeys("/ghi?\", "xt")', 'E486:') + call assert_fails('call feedkeys("?\\", "xt")', 'E486:') + call assert_equal('ghi\?', histget('/', -1)) + + set history& +endfunc + +" Test for making sure the key value is not stored in history +func Test_history_crypt_key() + CheckFeature cryptv + call feedkeys(":set bs=2 key=abc ts=8\", 'xt') + call assert_equal('set bs=2 key= ts=8', histget(':')) + set key& bs& ts& +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 5821c857e025a292c17bd80192366dc7bfb1fbc6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 1 Oct 2023 18:26:14 +0800 Subject: vim-patch:9.0.1968: cmdline completion should consider key option Problem: cmdline completion should consider key option Solution: Disable cmdline completion for key option, slightly refactor how P_NO_CMD_EXPAND is handled Harden crypto 'key' option: turn off cmdline completion, disable set-= "set-=" can be used maliciously with a crypto key, as it allows an attacker (who either has access to the computer or a plugin author) to guess a substring by observing the modified state. Simply turn off set+=/-=/^= for this option as there is no good reason for them to be used. Update docs to make that clear as well. Also, don't allow cmdline completion for 'key' as it just shows ***** which is not useful and confusing to the user what it means (if the user accidentally hits enter they will have replaced their key with "*****" instead). Move logic to better location, don't use above 32-bit for flags Move P_NO_CMD_EXPAND to use the unused 0x20 instead of going above 32-bits, as currently the flags parameter is only 32-bits on some systems. Left a comment to warn that future additions will need to change how the flags work either by making it 64-bit or split into two member vars. Also, move the logic for detecting P_NO_CMD_EXPAND earlier so it's not up to each handler to decide, and you won't see the temporary "..." that Vim shows while waiting for completion handler to complete. closes: vim/vim#13224 https://github.com/vim/vim/commit/6ee7b521fa7531ef356ececc8be7575c3800f872 Co-authored-by: Yee Cheng Chin --- test/old/testdir/test_history.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/old/testdir/test_history.vim') diff --git a/test/old/testdir/test_history.vim b/test/old/testdir/test_history.vim index f1c31dee04..bb6d671725 100644 --- a/test/old/testdir/test_history.vim +++ b/test/old/testdir/test_history.vim @@ -244,8 +244,13 @@ endfunc " Test for making sure the key value is not stored in history func Test_history_crypt_key() CheckFeature cryptv + call feedkeys(":set bs=2 key=abc ts=8\", 'xt') call assert_equal('set bs=2 key= ts=8', histget(':')) + + call assert_fails("call feedkeys(':set bs=2 key-=abc ts=8\', 'xt')") + call assert_equal('set bs=2 key-= ts=8', histget(':')) + set key& bs& ts& endfunc -- cgit From 9dc440400cdb470b317c4169ba916e1cd9a316e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 27 Oct 2023 06:37:52 +0800 Subject: vim-patch:9.0.2068: [security] overflow in :history (#25794) Problem: [security] overflow in :history Solution: Check that value fits into int The get_list_range() function, used to parse numbers for the :history and :clist command internally uses long variables to store the numbers. However function arguments are integer pointers, which can then overflow. Check that the return value from the vim_str2nr() function is not larger than INT_MAX and if yes, bail out with an error. I guess nobody uses a cmdline/clist history that needs so many entries... (famous last words). It is only a moderate vulnerability, so impact should be low. Github Advisory: https://github.com/vim/vim/security/advisories/GHSA-q22m-h7m2-9mgm https://github.com/vim/vim/commit/9198c1f2b1ddecde22af918541e0de2a32f0f45a N/A patch: vim-patch:9.0.2073: typo in quickfix.c comments Co-authored-by: Christian Brabandt --- test/old/testdir/test_history.vim | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/old/testdir/test_history.vim') diff --git a/test/old/testdir/test_history.vim b/test/old/testdir/test_history.vim index bb6d671725..482328ab4a 100644 --- a/test/old/testdir/test_history.vim +++ b/test/old/testdir/test_history.vim @@ -254,4 +254,12 @@ func Test_history_crypt_key() set key& bs& ts& endfunc +" The following used to overflow and causing an use-after-free +func Test_history_max_val() + + set history=10 + call assert_fails(':history 2147483648', 'E1510:') + set history& +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit