mirror of
https://github.com/neovim/neovim.git
synced 2025-10-10 03:46:31 +00:00
vim-patch:9.1.1802: 'nowrap' in a modeline may hide malicious code (#35946)
Problem: 'nowrap' in a modeline may hide malicious code. Solution: Forcibly use '>' as 'listchars' "extends" if 'nowrap' was set from a modeline (zeertzjq). Manual `:setlocal nowrap` disables this behavior. There is a separate problem with `:set nowrap` that also applies to some other options. related: vim/vim#18214 related: vim/vim#18399 closes: vim/vim#184259d5208a931
Cherry-pick some test_modeline.vim changes from patches 9.0.{0363,0626}. (cherry picked from commit0fa0717d4e
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
7280b7027b
commit
9c09983068
@@ -7311,6 +7311,11 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
< See 'sidescroll', 'listchars' and |wrap-off|.
|
||||
This option can't be set from a |modeline| when the 'diff' option is
|
||||
on.
|
||||
If 'nowrap' was set from a |modeline| or in the |sandbox|, '>' is used
|
||||
as the |lcs-extends| character regardless of the value of the 'list'
|
||||
and 'listchars' options. This is to prevent malicious code outside
|
||||
the viewport from going unnoticed. Use `:setlocal nowrap` manually
|
||||
afterwards to disable this behavior.
|
||||
|
||||
*'wrapmargin'* *'wm'*
|
||||
'wrapmargin' 'wm' number (default 0)
|
||||
|
5
runtime/lua/vim/_meta/options.lua
generated
5
runtime/lua/vim/_meta/options.lua
generated
@@ -8030,6 +8030,11 @@ vim.go.wiw = vim.go.winwidth
|
||||
--- See 'sidescroll', 'listchars' and `wrap-off`.
|
||||
--- This option can't be set from a `modeline` when the 'diff' option is
|
||||
--- on.
|
||||
--- If 'nowrap' was set from a `modeline` or in the `sandbox`, '>' is used
|
||||
--- as the `lcs-extends` character regardless of the value of the 'list'
|
||||
--- and 'listchars' options. This is to prevent malicious code outside
|
||||
--- the viewport from going unnoticed. Use `:setlocal nowrap` manually
|
||||
--- afterwards to disable this behavior.
|
||||
---
|
||||
--- @type boolean
|
||||
vim.o.wrap = true
|
||||
|
@@ -1257,6 +1257,7 @@ struct window_S {
|
||||
#define GLOBAL_WO(p) ((char *)(p) + sizeof(winopt_T))
|
||||
|
||||
// A few options have local flags for kOptFlagInsecure.
|
||||
uint32_t w_p_wrap_flags; // flags for 'wrap'
|
||||
uint32_t w_p_stl_flags; // flags for 'statusline'
|
||||
uint32_t w_p_wbr_flags; // flags for 'winbar'
|
||||
uint32_t w_p_fde_flags; // flags for 'foldexpr'
|
||||
|
@@ -155,6 +155,21 @@ void drawline_free_all_mem(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Get the 'listchars' "extends" characters to use for "wp", or NUL if it
|
||||
/// shouldn't be used.
|
||||
static schar_T get_lcs_ext(win_T *wp)
|
||||
{
|
||||
if (wp->w_p_wrap) {
|
||||
// Line never continues beyond the right of the screen with 'wrap'.
|
||||
return NUL;
|
||||
}
|
||||
if (wp->w_p_wrap_flags & kOptFlagInsecure) {
|
||||
// If 'nowrap' was set from a modeline, forcibly use '>'.
|
||||
return schar_from_ascii('>');
|
||||
}
|
||||
return wp->w_p_list ? wp->w_p_lcs_chars.ext : NUL;
|
||||
}
|
||||
|
||||
/// Advance wlv->color_cols if not NULL
|
||||
static void advance_color_col(winlinevars_T *wlv, int vcol)
|
||||
{
|
||||
@@ -2808,12 +2823,9 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b
|
||||
break;
|
||||
}
|
||||
|
||||
// Show "extends" character from 'listchars' if beyond the line end and
|
||||
// 'list' is set.
|
||||
// Don't show this with 'wrap' as the line can't be scrolled horizontally.
|
||||
if (wp->w_p_lcs_chars.ext != NUL
|
||||
&& wp->w_p_list
|
||||
&& !wp->w_p_wrap
|
||||
// Show "extends" character from 'listchars' if beyond the line end.
|
||||
const schar_T lcs_ext = get_lcs_ext(wp);
|
||||
if (lcs_ext != NUL
|
||||
&& wlv.filler_todo <= 0
|
||||
&& wlv.col == grid->cols - 1
|
||||
&& !has_foldtext) {
|
||||
@@ -2825,7 +2837,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b
|
||||
|| (lcs_eol > 0 && lcs_eol_todo)
|
||||
|| (wlv.n_extra > 0 && (wlv.sc_extra != NUL || *wlv.p_extra != NUL))
|
||||
|| (may_have_inline_virt && has_more_inline_virt(&wlv, ptr - line))) {
|
||||
mb_schar = wp->w_p_lcs_chars.ext;
|
||||
mb_schar = lcs_ext;
|
||||
wlv.char_attr = win_hl_attr(wp, HLF_AT);
|
||||
mb_c = schar_get_first_codepoint(mb_schar);
|
||||
}
|
||||
|
@@ -1676,6 +1676,8 @@ uint32_t *insecure_flag(win_T *const wp, OptIndex opt_idx, int opt_flags)
|
||||
if (opt_flags & OPT_LOCAL) {
|
||||
assert(wp != NULL);
|
||||
switch (opt_idx) {
|
||||
case kOptWrap:
|
||||
return &wp->w_p_wrap_flags;
|
||||
case kOptStatusline:
|
||||
return &wp->w_p_stl_flags;
|
||||
case kOptWinbar:
|
||||
|
@@ -10435,6 +10435,11 @@ local options = {
|
||||
< See 'sidescroll', 'listchars' and |wrap-off|.
|
||||
This option can't be set from a |modeline| when the 'diff' option is
|
||||
on.
|
||||
If 'nowrap' was set from a |modeline| or in the |sandbox|, '>' is used
|
||||
as the |lcs-extends| character regardless of the value of the 'list'
|
||||
and 'listchars' options. This is to prevent malicious code outside
|
||||
the viewport from going unnoticed. Use `:setlocal nowrap` manually
|
||||
afterwards to disable this behavior.
|
||||
]=],
|
||||
full_name = 'wrap',
|
||||
redraw = { 'current_window' },
|
||||
|
@@ -358,22 +358,69 @@ endfunc
|
||||
|
||||
" Some options cannot be set from the modeline when 'diff' option is set
|
||||
func Test_modeline_diff_buffer()
|
||||
call writefile(['vim: diff foldmethod=marker wrap'], 'Xfile')
|
||||
call writefile(['vim: diff foldmethod=marker wrap'], 'Xmdifile', 'D')
|
||||
set foldmethod& nowrap
|
||||
new Xfile
|
||||
new Xmdifile
|
||||
call assert_equal('manual', &foldmethod)
|
||||
call assert_false(&wrap)
|
||||
set wrap&
|
||||
call delete('Xfile')
|
||||
bw
|
||||
endfunc
|
||||
|
||||
func Test_modeline_disable()
|
||||
set modeline
|
||||
call writefile(['vim: sw=2', 'vim: nomodeline', 'vim: sw=3'], 'Xmodeline_disable')
|
||||
call writefile(['vim: sw=2', 'vim: nomodeline', 'vim: sw=3'], 'Xmodeline_disable', 'D')
|
||||
edit Xmodeline_disable
|
||||
call assert_equal(2, &sw)
|
||||
call delete('Xmodeline_disable')
|
||||
endfunc
|
||||
|
||||
" If 'nowrap' is set from a modeline, '>' is used forcibly as lcs-extends.
|
||||
func Test_modeline_nowrap_lcs_extends()
|
||||
call writefile([
|
||||
\ 'aaa',
|
||||
\ 'bbb',
|
||||
\ 'ccc evil',
|
||||
\ 'ddd vim: nowrap',
|
||||
\ ], 'Xmodeline_nowrap', 'D')
|
||||
call NewWindow(10, 20)
|
||||
|
||||
setlocal nolist listchars=
|
||||
edit Xmodeline_nowrap
|
||||
let expect_insecure = [
|
||||
\ 'aaa ',
|
||||
\ 'bbb ',
|
||||
\ 'ccc >',
|
||||
\ 'ddd >',
|
||||
\ '~ ',
|
||||
\ ]
|
||||
call assert_equal(expect_insecure, ScreenLines([1, 5], 20))
|
||||
|
||||
setlocal nowrap
|
||||
let expect_secure = [
|
||||
\ 'aaa ',
|
||||
\ 'bbb ',
|
||||
\ 'ccc ',
|
||||
\ 'ddd ',
|
||||
\ '~ ',
|
||||
\ ]
|
||||
call assert_equal(expect_secure, ScreenLines([1, 5], 20))
|
||||
|
||||
setlocal list listchars=extends:+
|
||||
let expect_secure = [
|
||||
\ 'aaa ',
|
||||
\ 'bbb ',
|
||||
\ 'ccc +',
|
||||
\ 'ddd +',
|
||||
\ '~ ',
|
||||
\ ]
|
||||
call assert_equal(expect_secure, ScreenLines([1, 5], 20))
|
||||
|
||||
edit Xmodeline_nowrap
|
||||
call assert_equal(expect_insecure, ScreenLines([1, 5], 20))
|
||||
setlocal nowrap
|
||||
call assert_equal(expect_secure, ScreenLines([1, 5], 20))
|
||||
|
||||
call CloseWindow()
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Reference in New Issue
Block a user