diff options
author | James McCoy <jamessan@jamessan.com> | 2016-11-20 08:42:38 -0700 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2016-11-20 14:07:46 -0500 |
commit | 4fad66fbe637818b6b3d6bc5d21923ba72795040 (patch) | |
tree | f35fd84189d2c4bebe739bfc5ad3fec1780d1f4c /src/nvim/option.c | |
parent | 42033bc5bd4bd0f06b33391e12672900bc21b993 (diff) | |
download | rneovim-4fad66fbe637818b6b3d6bc5d21923ba72795040.tar.gz rneovim-4fad66fbe637818b6b3d6bc5d21923ba72795040.tar.bz2 rneovim-4fad66fbe637818b6b3d6bc5d21923ba72795040.zip |
vim-patch:8.0.0056
Problem: When setting 'filetype' there is no check for a valid name.
Solution: Only allow valid characters in 'filetype', 'syntax' and 'keymap'.
https://github.com/vim/vim/commit/d0b5138ba4bccff8a744c99836041ef6322ed39a
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r-- | src/nvim/option.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 0f95974cb4..469aeecc23 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2399,6 +2399,18 @@ static char *set_string_option(const int opt_idx, const char *const value, return r; } +/// Return true if "val" is a valid 'filetype' name. +/// Also used for 'syntax' and 'keymap'. +static bool valid_filetype(char_u *val) +{ + for (char_u *s = val; *s != NUL; s++) { + if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL) { + return false; + } + } + return true; +} + /* * Handle string options that need some action to perform when changed. * Returns NULL for success, or an error message for an error. @@ -2623,8 +2635,12 @@ did_set_string_option ( xfree(p_penc); p_penc = p; } else if (varp == &curbuf->b_p_keymap) { - /* load or unload key mapping tables */ - errmsg = keymap_init(); + if (!valid_filetype(*varp)) { + errmsg = e_invarg; + } else { + // load or unload key mapping tables + errmsg = keymap_init(); + } if (errmsg == NULL) { if (*curbuf->b_p_keymap != NUL) { @@ -3118,8 +3134,16 @@ did_set_string_option ( if (check_opt_strings(p_icm, p_icm_values, false) != OK) { errmsg = e_invarg; } - // Options that are a list of flags. + } else if (gvarp == &p_ft) { + if (!valid_filetype(*varp)) { + errmsg = e_invarg; + } + } else if (gvarp == &p_syn) { + if (!valid_filetype(*varp)) { + errmsg = e_invarg; + } } else { + // Options that are a list of flags. p = NULL; if (varp == &p_ww) p = (char_u *)WW_ALL; |