aboutsummaryrefslogtreecommitdiffstats
path: root/main/vim/CVE-2016-1248.patch
blob: ecaf6d33741f74284cf8042e2f88f36bf7421c57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
From d0b5138ba4bccff8a744c99836041ef6322ed39a Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
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,