summaryrefslogtreecommitdiffstats
path: root/src/option.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-11-04 15:23:45 +0100
committerBram Moolenaar <Bram@vim.org>2016-11-04 15:23:45 +0100
commitd0b5138ba4bccff8a744c99836041ef6322ed39a (patch)
tree8a0501fe13f964392121d84fa95be9791fe32f4e /src/option.c
parent3a117e19e02bf29cfc5e398470dd7851ae3d6803 (diff)
patch 8.0.0056v8.0.0056
Problem: When setting 'filetype' there is no check for a valid name. Solution: Only allow valid characters in 'filetype', 'syntax' and 'keymap'.
Diffstat (limited to 'src/option.c')
-rw-r--r--src/option.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/option.c b/src/option.c
index ebf443b84b..8eea1f8766 100644
--- a/src/option.c
+++ b/src/option.c
@@ -5823,6 +5823,21 @@ set_string_option(
}
/*
+ * Return TRUE if "val" is a valid 'filetype' name.
+ * Also used for 'syntax' and 'keymap'.
+ */
+ static int
+valid_filetype(char_u *val)
+{
+ char_u *s;
+
+ for (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.
*/
@@ -6235,8 +6250,11 @@ did_set_string_option(
#ifdef FEAT_KEYMAP
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)
{
@@ -7222,6 +7240,22 @@ did_set_string_option(
}
#endif
+#ifdef FEAT_AUTOCMD
+ else if (gvarp == &p_ft)
+ {
+ if (!valid_filetype(*varp))
+ errmsg = e_invarg;
+ }
+#endif
+
+#ifdef FEAT_SYN_HL
+ else if (gvarp == &p_syn)
+ {
+ if (!valid_filetype(*varp))
+ errmsg = e_invarg;
+ }
+#endif
+
/* Options that are a list of flags. */
else
{