Mercurial > vim
comparison src/option.c @ 10322:5adc318767be v8.0.0056
commit https://github.com/vim/vim/commit/d0b5138ba4bccff8a744c99836041ef6322ed39a
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Nov 4 15:23:45 2016 +0100
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'.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 04 Nov 2016 15:30:07 +0100 |
parents | c55a7232fb48 |
children | 54249c31882a |
comparison
equal
deleted
inserted
replaced
10321:a6b2b5a27cbc | 10322:5adc318767be |
---|---|
5821 } | 5821 } |
5822 return r; | 5822 return r; |
5823 } | 5823 } |
5824 | 5824 |
5825 /* | 5825 /* |
5826 * Return TRUE if "val" is a valid 'filetype' name. | |
5827 * Also used for 'syntax' and 'keymap'. | |
5828 */ | |
5829 static int | |
5830 valid_filetype(char_u *val) | |
5831 { | |
5832 char_u *s; | |
5833 | |
5834 for (s = val; *s != NUL; ++s) | |
5835 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL) | |
5836 return FALSE; | |
5837 return TRUE; | |
5838 } | |
5839 | |
5840 /* | |
5826 * Handle string options that need some action to perform when changed. | 5841 * Handle string options that need some action to perform when changed. |
5827 * Returns NULL for success, or an error message for an error. | 5842 * Returns NULL for success, or an error message for an error. |
5828 */ | 5843 */ |
5829 static char_u * | 5844 static char_u * |
5830 did_set_string_option( | 5845 did_set_string_option( |
6233 #endif | 6248 #endif |
6234 | 6249 |
6235 #ifdef FEAT_KEYMAP | 6250 #ifdef FEAT_KEYMAP |
6236 else if (varp == &curbuf->b_p_keymap) | 6251 else if (varp == &curbuf->b_p_keymap) |
6237 { | 6252 { |
6238 /* load or unload key mapping tables */ | 6253 if (!valid_filetype(*varp)) |
6239 errmsg = keymap_init(); | 6254 errmsg = e_invarg; |
6255 else | |
6256 /* load or unload key mapping tables */ | |
6257 errmsg = keymap_init(); | |
6240 | 6258 |
6241 if (errmsg == NULL) | 6259 if (errmsg == NULL) |
6242 { | 6260 { |
6243 if (*curbuf->b_p_keymap != NUL) | 6261 if (*curbuf->b_p_keymap != NUL) |
6244 { | 6262 { |
7216 | 7234 |
7217 #if defined(FEAT_RENDER_OPTIONS) | 7235 #if defined(FEAT_RENDER_OPTIONS) |
7218 else if (varp == &p_rop && gui.in_use) | 7236 else if (varp == &p_rop && gui.in_use) |
7219 { | 7237 { |
7220 if (!gui_mch_set_rendering_options(p_rop)) | 7238 if (!gui_mch_set_rendering_options(p_rop)) |
7239 errmsg = e_invarg; | |
7240 } | |
7241 #endif | |
7242 | |
7243 #ifdef FEAT_AUTOCMD | |
7244 else if (gvarp == &p_ft) | |
7245 { | |
7246 if (!valid_filetype(*varp)) | |
7247 errmsg = e_invarg; | |
7248 } | |
7249 #endif | |
7250 | |
7251 #ifdef FEAT_SYN_HL | |
7252 else if (gvarp == &p_syn) | |
7253 { | |
7254 if (!valid_filetype(*varp)) | |
7221 errmsg = e_invarg; | 7255 errmsg = e_invarg; |
7222 } | 7256 } |
7223 #endif | 7257 #endif |
7224 | 7258 |
7225 /* Options that are a list of flags. */ | 7259 /* Options that are a list of flags. */ |