Skip to content

Commit 9cf4b50

Browse files
committed
patch 8.1.0205: invalid memory access with invalid modeline
Problem: Invalid memory access with invalid modeline. Solution: Pass pointer limit. Add a test. (closes #3241)
1 parent 947b39e commit 9cf4b50

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

src/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ NEW_TESTS = \
118118
test_messages \
119119
test_mksession \
120120
test_mksession_utf8 \
121+
test_modeline \
121122
test_nested_function \
122123
test_netbeans \
123124
test_normal \

src/option.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,7 +3316,7 @@ static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_fla
33163316
static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
33173317
static void check_redraw(long_u flags);
33183318
static int findoption(char_u *);
3319-
static int find_key_option(char_u *);
3319+
static int find_key_option(char_u *arg_arg, int has_lt);
33203320
static void showoptions(int all, int opt_flags);
33213321
static int optval_default(struct vimoption *, char_u *varp);
33223322
static void showoneopt(struct vimoption *, int opt_flags);
@@ -4492,7 +4492,7 @@ do_set(
44924492
opt_idx = findoption(arg + 1);
44934493
arg[len++] = '>'; /* restore '>' */
44944494
if (opt_idx == -1)
4495-
key = find_key_option(arg + 1);
4495+
key = find_key_option(arg + 1, TRUE);
44964496
}
44974497
else
44984498
{
@@ -4510,7 +4510,7 @@ do_set(
45104510
opt_idx = findoption(arg);
45114511
arg[len] = nextchar; /* restore nextchar */
45124512
if (opt_idx == -1)
4513-
key = find_key_option(arg);
4513+
key = find_key_option(arg, FALSE);
45144514
}
45154515

45164516
/* remember character after option name */
@@ -5362,7 +5362,7 @@ illegal_char(char_u *errbuf, int c)
53625362
string_to_key(char_u *arg, int multi_byte)
53635363
{
53645364
if (*arg == '<')
5365-
return find_key_option(arg + 1);
5365+
return find_key_option(arg + 1, TRUE);
53665366
if (*arg == '^')
53675367
return Ctrl_chr(arg[1]);
53685368
if (multi_byte)
@@ -9541,7 +9541,7 @@ get_option_value(
95419541
int key;
95429542

95439543
if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9544-
&& (key = find_key_option(name)) != 0)
9544+
&& (key = find_key_option(name, FALSE)) != 0)
95459545
{
95469546
char_u key_name[2];
95479547
char_u *p;
@@ -9831,7 +9831,7 @@ set_option_value(
98319831
int key;
98329832

98339833
if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9834-
&& (key = find_key_option(name)) != 0)
9834+
&& (key = find_key_option(name, FALSE)) != 0)
98359835
{
98369836
char_u key_name[2];
98379837

@@ -9952,20 +9952,23 @@ get_encoding_default(void)
99529952

99539953
/*
99549954
* Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9955+
* When "has_lt" is true there is a '<' before "*arg_arg".
9956+
* Returns 0 when the key is not recognized.
99559957
*/
99569958
static int
9957-
find_key_option(char_u *arg)
9959+
find_key_option(char_u *arg_arg, int has_lt)
99589960
{
9959-
int key;
9961+
int key = 0;
99609962
int modifiers;
9963+
char_u *arg = arg_arg;
99619964

99629965
/*
99639966
* Don't use get_special_key_code() for t_xx, we don't want it to call
99649967
* add_termcap_entry().
99659968
*/
99669969
if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
99679970
key = TERMCAP2KEY(arg[2], arg[3]);
9968-
else
9971+
else if (has_lt)
99699972
{
99709973
--arg; /* put arg at the '<' */
99719974
modifiers = 0;

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ source test_mapping.vim
3737
source test_match.vim
3838
source test_menu.vim
3939
source test_messages.vim
40+
source test_modeline.vim
4041
source test_partial.vim
4142
source test_popup.vim
4243
source test_put.vim

src/testdir/test_modeline.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
" Tests for parsing the modeline.
2+
3+
func Test_invalid()
4+
" This was reading before allocated memory.
5+
call writefile(['vi:0', 'nothing'], 'Xmodeline')
6+
call assert_fails('split Xmodeline', 'E518:')
7+
bwipe!
8+
endfunc

src/version.c

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

794794
static int included_patches[] =
795795
{ /* Add new patch number below this line */
796+
/**/
797+
205,
796798
/**/
797799
204,
798800
/**/

0 commit comments

Comments
 (0)