From d0b5138ba4bccff8a744c99836041ef6322ed39a Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 4 Nov 2016 15:23:45 +0100 Subject: [PATCH] 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'. --- src/option.c | 38 ++++++++++++++++++++++++++++++++-- src/version.c | 2 ++ 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/option.c b/src/option.c index ebf443b..8eea1f8 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 { diff --git a/src/version.c b/src/version.c index 0b62f9c..f63041e 100644 --- a/src/version.c +++ b/src/version.c @@ -765,6 +765,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 56, +/**/ 55, /**/ 54,