Skip to content

Commit 75661a6

Browse files
committed
patch 9.2.0276: [security]: modeline security bypass
Problem: [security]: modeline security bypass Solution: disallow mapset() from secure mode, set the P_MLE flag for the 'complete', 'guitabtooltip' and 'printheader' options. Github Advisory: GHSA-8h6p-m6gr-mpw9 Signed-off-by: Christian Brabandt <[email protected]>
1 parent 4cc3ab7 commit 75661a6

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/map.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,6 +2746,9 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
27462746
int dict_only;
27472747
mapblock_T *mp_result[2] = {NULL, NULL};
27482748

2749+
if (check_secure())
2750+
return;
2751+
27492752
// If first arg is a dict, then that's the only arg permitted.
27502753
dict_only = argvars[0].v_type == VAR_DICT;
27512754
if (in_vim9script()

src/optiondefs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ static struct vimoption options[] =
681681
{"compatible", "cp", P_BOOL|P_RALL,
682682
(char_u *)&p_cp, PV_NONE, did_set_compatible, NULL,
683683
{(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
684-
{"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
684+
{"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP|P_MLE,
685685
(char_u *)&p_cpt, PV_CPT, did_set_complete, expand_set_complete,
686686
{(char_u *)".,w,b,u,t,i", (char_u *)0L}
687687
SCTX_INIT},
@@ -1324,7 +1324,7 @@ static struct vimoption options[] =
13241324
{(char_u *)NULL, (char_u *)0L}
13251325
#endif
13261326
SCTX_INIT},
1327-
{"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
1327+
{"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
13281328
#if defined(FEAT_GUI_TABLINE)
13291329
(char_u *)&p_gtt, PV_NONE, NULL, NULL,
13301330
{(char_u *)"", (char_u *)0L}
@@ -2041,7 +2041,7 @@ static struct vimoption options[] =
20412041
{(char_u *)NULL, (char_u *)0L}
20422042
#endif
20432043
SCTX_INIT},
2044-
{"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2044+
{"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT|P_MLE,
20452045
#ifdef FEAT_PRINTER
20462046
(char_u *)&p_header, PV_NONE, NULL, NULL,
20472047
// untranslated to avoid problems when 'encoding'

src/testdir/test_modeline.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,4 +490,29 @@ func Test_modeline_nowrap_lcs_extends()
490490
set equalalways&
491491
endfunc
492492

493+
func Test_modeline_forbidden()
494+
let tempfile = tempname()
495+
let lines =<< trim END
496+
some test text for completion
497+
vim: set complete=F{->system('touch_should_not_run')} :
498+
END
499+
call writefile(lines, tempfile, 'D')
500+
call assert_fails($'new {tempfile}', 'E992:')
501+
bw!
502+
let lines =<< trim END
503+
some text
504+
vim: set guitabtooltip=%{%mapset()%}:
505+
END
506+
call writefile(lines, tempfile)
507+
call assert_fails($'new {tempfile}', 'E992:')
508+
bw!
509+
let lines =<< trim END
510+
some text
511+
vim: set printheader=%{mapset('n',0,{})%)%}:
512+
END
513+
call writefile(lines, tempfile, 'D')
514+
call assert_fails($'new {tempfile}', 'E992:')
515+
bw!
516+
endfunc
517+
493518
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
276,
737739
/**/
738740
275,
739741
/**/

0 commit comments

Comments
 (0)