Skip to content

Commit 247bb7e

Browse files
committed
patch 8.1.0540: may evaluate insecure value when appending to option
Problem: May evaluate insecure value when appending to option. Solution: Set the secure flag when changing an option that was previously set insecurely. Also allow numbers for the characters from 'spelllang' that are used for LANG.vim.
1 parent 82e8c92 commit 247bb7e

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

src/option.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4705,6 +4705,8 @@ do_set(
47054705
}
47064706
else
47074707
{
4708+
int value_is_replaced = !prepending && !adding && !removing;
4709+
47084710
if (flags & P_BOOL) /* boolean */
47094711
{
47104712
if (nextchar == '=' || nextchar == ':')
@@ -5209,12 +5211,36 @@ do_set(
52095211
}
52105212
#endif
52115213

5212-
/* Handle side effects, and set the global value for
5213-
* ":set" on local options. Note: when setting 'syntax'
5214-
* or 'filetype' autocommands may be triggered that can
5215-
* cause havoc. */
5216-
errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5217-
new_value_alloced, oldval, errbuf, opt_flags);
5214+
{
5215+
long_u *p = insecure_flag(opt_idx, opt_flags);
5216+
int did_inc_secure = FALSE;
5217+
5218+
// When an option is set in the sandbox, from a
5219+
// modeline or in secure mode, then deal with side
5220+
// effects in secure mode. Also when the value was
5221+
// set with the P_INSECURE flag and is not
5222+
// completely replaced.
5223+
if (secure
5224+
#ifdef HAVE_SANDBOX
5225+
|| sandbox != 0
5226+
#endif
5227+
|| (opt_flags & OPT_MODELINE)
5228+
|| (!value_is_replaced && (*p & P_INSECURE)))
5229+
{
5230+
did_inc_secure = TRUE;
5231+
++secure;
5232+
}
5233+
5234+
// Handle side effects, and set the global value for
5235+
// ":set" on local options. Note: when setting 'syntax'
5236+
// or 'filetype' autocommands may be triggered that can
5237+
// cause havoc.
5238+
errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5239+
new_value_alloced, oldval, errbuf, opt_flags);
5240+
5241+
if (did_inc_secure)
5242+
--secure;
5243+
}
52185244

52195245
#if defined(FEAT_EVAL)
52205246
if (errmsg == NULL)
@@ -5254,8 +5280,7 @@ do_set(
52545280
}
52555281

52565282
if (opt_idx >= 0)
5257-
did_set_option(opt_idx, opt_flags,
5258-
!prepending && !adding && !removing);
5283+
did_set_option(opt_idx, opt_flags, value_is_replaced);
52595284
}
52605285

52615286
skip:
@@ -7758,7 +7783,7 @@ did_set_string_option(
77587783
* '.encoding'.
77597784
*/
77607785
for (p = q; *p != NUL; ++p)
7761-
if (!ASCII_ISALPHA(*p) && *p != '-')
7786+
if (!ASCII_ISALNUM(*p) && *p != '-')
77627787
break;
77637788
if (p > q)
77647789
{

src/version.c

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

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
540,
795797
/**/
796798
539,
797799
/**/

0 commit comments

Comments
 (0)