Mercurial > vim
comparison src/option.c @ 14381:d9e6eec551e1 v8.1.0205
patch 8.1.0205: invalid memory access with invalid modeline
commit https://github.com/vim/vim/commit/9cf4b5005f12ce1d6692266140bdda05d0312d79
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jul 23 04:12:03 2018 +0200
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 https://github.com/vim/vim/issues/3241)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 23 Jul 2018 04:15:05 +0200 |
parents | 37ed47b58f54 |
children | 3375a8cbb442 |
comparison
equal
deleted
inserted
replaced
14380:116b909126bd | 14381:d9e6eec551e1 |
---|---|
3314 #endif | 3314 #endif |
3315 static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags); | 3315 static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags); |
3316 static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags); | 3316 static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags); |
3317 static void check_redraw(long_u flags); | 3317 static void check_redraw(long_u flags); |
3318 static int findoption(char_u *); | 3318 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); |
3320 static void showoptions(int all, int opt_flags); | 3320 static void showoptions(int all, int opt_flags); |
3321 static int optval_default(struct vimoption *, char_u *varp); | 3321 static int optval_default(struct vimoption *, char_u *varp); |
3322 static void showoneopt(struct vimoption *, int opt_flags); | 3322 static void showoneopt(struct vimoption *, int opt_flags); |
3323 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand); | 3323 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand); |
3324 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep); | 3324 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep); |
4490 arg[len] = NUL; /* put NUL after name */ | 4490 arg[len] = NUL; /* put NUL after name */ |
4491 if (arg[1] == 't' && arg[2] == '_') /* could be term code */ | 4491 if (arg[1] == 't' && arg[2] == '_') /* could be term code */ |
4492 opt_idx = findoption(arg + 1); | 4492 opt_idx = findoption(arg + 1); |
4493 arg[len++] = '>'; /* restore '>' */ | 4493 arg[len++] = '>'; /* restore '>' */ |
4494 if (opt_idx == -1) | 4494 if (opt_idx == -1) |
4495 key = find_key_option(arg + 1); | 4495 key = find_key_option(arg + 1, TRUE); |
4496 } | 4496 } |
4497 else | 4497 else |
4498 { | 4498 { |
4499 len = 0; | 4499 len = 0; |
4500 /* | 4500 /* |
4508 nextchar = arg[len]; | 4508 nextchar = arg[len]; |
4509 arg[len] = NUL; /* put NUL after name */ | 4509 arg[len] = NUL; /* put NUL after name */ |
4510 opt_idx = findoption(arg); | 4510 opt_idx = findoption(arg); |
4511 arg[len] = nextchar; /* restore nextchar */ | 4511 arg[len] = nextchar; /* restore nextchar */ |
4512 if (opt_idx == -1) | 4512 if (opt_idx == -1) |
4513 key = find_key_option(arg); | 4513 key = find_key_option(arg, FALSE); |
4514 } | 4514 } |
4515 | 4515 |
4516 /* remember character after option name */ | 4516 /* remember character after option name */ |
4517 afterchar = arg[len]; | 4517 afterchar = arg[len]; |
4518 | 4518 |
5360 */ | 5360 */ |
5361 int | 5361 int |
5362 string_to_key(char_u *arg, int multi_byte) | 5362 string_to_key(char_u *arg, int multi_byte) |
5363 { | 5363 { |
5364 if (*arg == '<') | 5364 if (*arg == '<') |
5365 return find_key_option(arg + 1); | 5365 return find_key_option(arg + 1, TRUE); |
5366 if (*arg == '^') | 5366 if (*arg == '^') |
5367 return Ctrl_chr(arg[1]); | 5367 return Ctrl_chr(arg[1]); |
5368 if (multi_byte) | 5368 if (multi_byte) |
5369 return PTR2CHAR(arg); | 5369 return PTR2CHAR(arg); |
5370 return *arg; | 5370 return *arg; |
9539 if (opt_idx < 0) /* unknown option */ | 9539 if (opt_idx < 0) /* unknown option */ |
9540 { | 9540 { |
9541 int key; | 9541 int key; |
9542 | 9542 |
9543 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' | 9543 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
9544 && (key = find_key_option(name)) != 0) | 9544 && (key = find_key_option(name, FALSE)) != 0) |
9545 { | 9545 { |
9546 char_u key_name[2]; | 9546 char_u key_name[2]; |
9547 char_u *p; | 9547 char_u *p; |
9548 | 9548 |
9549 if (key < 0) | 9549 if (key < 0) |
9829 if (opt_idx < 0) | 9829 if (opt_idx < 0) |
9830 { | 9830 { |
9831 int key; | 9831 int key; |
9832 | 9832 |
9833 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' | 9833 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' |
9834 && (key = find_key_option(name)) != 0) | 9834 && (key = find_key_option(name, FALSE)) != 0) |
9835 { | 9835 { |
9836 char_u key_name[2]; | 9836 char_u key_name[2]; |
9837 | 9837 |
9838 if (key < 0) | 9838 if (key < 0) |
9839 { | 9839 { |
9950 } | 9950 } |
9951 #endif | 9951 #endif |
9952 | 9952 |
9953 /* | 9953 /* |
9954 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number. | 9954 * 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. | |
9955 */ | 9957 */ |
9956 static int | 9958 static int |
9957 find_key_option(char_u *arg) | 9959 find_key_option(char_u *arg_arg, int has_lt) |
9958 { | 9960 { |
9959 int key; | 9961 int key = 0; |
9960 int modifiers; | 9962 int modifiers; |
9963 char_u *arg = arg_arg; | |
9961 | 9964 |
9962 /* | 9965 /* |
9963 * Don't use get_special_key_code() for t_xx, we don't want it to call | 9966 * Don't use get_special_key_code() for t_xx, we don't want it to call |
9964 * add_termcap_entry(). | 9967 * add_termcap_entry(). |
9965 */ | 9968 */ |
9966 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) | 9969 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) |
9967 key = TERMCAP2KEY(arg[2], arg[3]); | 9970 key = TERMCAP2KEY(arg[2], arg[3]); |
9968 else | 9971 else if (has_lt) |
9969 { | 9972 { |
9970 --arg; /* put arg at the '<' */ | 9973 --arg; /* put arg at the '<' */ |
9971 modifiers = 0; | 9974 modifiers = 0; |
9972 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE); | 9975 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE); |
9973 if (modifiers) /* can't handle modifiers here */ | 9976 if (modifiers) /* can't handle modifiers here */ |