]>
Commit | Line | Data |
---|---|---|
bab0032d AG |
1 | To: vim_dev@googlegroups.com |
2 | Subject: Patch 7.3.148 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.3.148 | |
11 | Problem: A syntax file with a huge number of items or clusters causes weird | |
12 | behavior, a hang or a crash. (Yukihiro Nakadaira) | |
13 | Solution: Check running out of IDs. (partly by Ben Schmidt) | |
14 | Files: src/syntax.c | |
15 | ||
16 | ||
17 | *** ../vim-7.3.147/src/syntax.c 2011-01-22 00:58:15.000000000 +0100 | |
18 | --- src/syntax.c 2011-04-01 14:25:39.000000000 +0200 | |
19 | *************** | |
20 | *** 219,234 **** | |
21 | ||
22 | /* | |
23 | * Syntax group IDs have different types: | |
24 | ! * 0 - 9999 normal syntax groups | |
25 | ! * 10000 - 14999 ALLBUT indicator (current_syn_inc_tag added) | |
26 | ! * 15000 - 19999 TOP indicator (current_syn_inc_tag added) | |
27 | ! * 20000 - 24999 CONTAINED indicator (current_syn_inc_tag added) | |
28 | ! * >= 25000 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) | |
29 | ! */ | |
30 | ! #define SYNID_ALLBUT 10000 /* syntax group ID for contains=ALLBUT */ | |
31 | ! #define SYNID_TOP 15000 /* syntax group ID for contains=TOP */ | |
32 | ! #define SYNID_CONTAINED 20000 /* syntax group ID for contains=CONTAINED */ | |
33 | ! #define SYNID_CLUSTER 25000 /* first syntax group ID for clusters */ | |
34 | ||
35 | /* | |
36 | * Annoying Hack(TM): ":syn include" needs this pointer to pass to | |
37 | --- 219,238 ---- | |
38 | ||
39 | /* | |
40 | * Syntax group IDs have different types: | |
41 | ! * 0 - 19999 normal syntax groups | |
42 | ! * 20000 - 20999 ALLBUT indicator (current_syn_inc_tag added) | |
43 | ! * 21000 - 21999 TOP indicator (current_syn_inc_tag added) | |
44 | ! * 22000 - 22999 CONTAINED indicator (current_syn_inc_tag added) | |
45 | ! * 23000 - 32767 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) | |
46 | ! */ | |
47 | ! #define SYNID_ALLBUT 20000 /* syntax group ID for contains=ALLBUT */ | |
48 | ! #define SYNID_TOP 21000 /* syntax group ID for contains=TOP */ | |
49 | ! #define SYNID_CONTAINED 22000 /* syntax group ID for contains=CONTAINED */ | |
50 | ! #define SYNID_CLUSTER 23000 /* first syntax group ID for clusters */ | |
51 | ! | |
52 | ! #define MAX_SYNID SYNID_ALLBUT | |
53 | ! #define MAX_SYN_INC_TAG 999 /* maximum before the above overflow */ | |
54 | ! #define MAX_CLUSTER_ID (32767 - SYNID_CLUSTER) | |
55 | ||
56 | /* | |
57 | * Annoying Hack(TM): ":syn include" needs this pointer to pass to | |
58 | *************** | |
59 | *** 3442,3447 **** | |
60 | --- 3446,3454 ---- | |
61 | /* free the stored states */ | |
62 | syn_stack_free_all(block); | |
63 | invalidate_current_state(); | |
64 | + | |
65 | + /* Reset the counter for ":syn include" */ | |
66 | + running_syn_inc_tag = 0; | |
67 | } | |
68 | ||
69 | /* | |
70 | *************** | |
71 | *** 4661,4666 **** | |
72 | --- 4668,4675 ---- | |
73 | return; | |
74 | } | |
75 | sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); | |
76 | + if (sgl_id == 0) | |
77 | + return; | |
78 | /* separate_nextcmd() and expand_filename() depend on this */ | |
79 | eap->arg = rest; | |
80 | } | |
81 | *************** | |
82 | *** 4689,4694 **** | |
83 | --- 4698,4708 ---- | |
84 | * Save and restore the existing top-level grouplist id and ":syn | |
85 | * include" tag around the actual inclusion. | |
86 | */ | |
87 | + if (running_syn_inc_tag >= MAX_SYN_INC_TAG) | |
88 | + { | |
89 | + EMSG((char_u *)_("E847: Too many syntax includes")); | |
90 | + return; | |
91 | + } | |
92 | prev_syn_inc_tag = current_syn_inc_tag; | |
93 | current_syn_inc_tag = ++running_syn_inc_tag; | |
94 | prev_toplvl_grp = curwin->w_s->b_syn_topgrp; | |
95 | *************** | |
96 | *** 4712,4718 **** | |
97 | char_u *group_name_end; | |
98 | int syn_id; | |
99 | char_u *rest; | |
100 | ! char_u *keyword_copy; | |
101 | char_u *p; | |
102 | char_u *kw; | |
103 | syn_opt_arg_T syn_opt_arg; | |
104 | --- 4726,4732 ---- | |
105 | char_u *group_name_end; | |
106 | int syn_id; | |
107 | char_u *rest; | |
108 | ! char_u *keyword_copy = NULL; | |
109 | char_u *p; | |
110 | char_u *kw; | |
111 | syn_opt_arg_T syn_opt_arg; | |
112 | *************** | |
113 | *** 4724,4732 **** | |
114 | if (rest != NULL) | |
115 | { | |
116 | syn_id = syn_check_group(arg, (int)(group_name_end - arg)); | |
117 | ! | |
118 | ! /* allocate a buffer, for removing the backslashes in the keyword */ | |
119 | ! keyword_copy = alloc((unsigned)STRLEN(rest) + 1); | |
120 | if (keyword_copy != NULL) | |
121 | { | |
122 | syn_opt_arg.flags = 0; | |
123 | --- 4738,4746 ---- | |
124 | if (rest != NULL) | |
125 | { | |
126 | syn_id = syn_check_group(arg, (int)(group_name_end - arg)); | |
127 | ! if (syn_id != 0) | |
128 | ! /* allocate a buffer, for removing backslashes in the keyword */ | |
129 | ! keyword_copy = alloc((unsigned)STRLEN(rest) + 1); | |
130 | if (keyword_copy != NULL) | |
131 | { | |
132 | syn_opt_arg.flags = 0; | |
133 | *************** | |
134 | *** 5133,5139 **** | |
135 | (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END; | |
136 | SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags; | |
137 | SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; | |
138 | ! SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = current_syn_inc_tag; | |
139 | SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = | |
140 | ppp->pp_matchgroup_id; | |
141 | #ifdef FEAT_CONCEAL | |
142 | --- 5147,5154 ---- | |
143 | (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END; | |
144 | SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags; | |
145 | SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; | |
146 | ! SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = | |
147 | ! current_syn_inc_tag; | |
148 | SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = | |
149 | ppp->pp_matchgroup_id; | |
150 | #ifdef FEAT_CONCEAL | |
151 | *************** | |
152 | *** 5426,5431 **** | |
153 | --- 5441,5454 ---- | |
154 | curwin->w_s->b_syn_clusters.ga_growsize = 10; | |
155 | } | |
156 | ||
157 | + len = curwin->w_s->b_syn_clusters.ga_len; | |
158 | + if (len >= MAX_CLUSTER_ID) | |
159 | + { | |
160 | + EMSG((char_u *)_("E848: Too many syntax clusters")); | |
161 | + vim_free(name); | |
162 | + return 0; | |
163 | + } | |
164 | + | |
165 | /* | |
166 | * Make room for at least one other cluster entry. | |
167 | */ | |
168 | *************** | |
169 | *** 5434,5440 **** | |
170 | vim_free(name); | |
171 | return 0; | |
172 | } | |
173 | - len = curwin->w_s->b_syn_clusters.ga_len; | |
174 | ||
175 | vim_memset(&(SYN_CLSTR(curwin->w_s)[len]), 0, sizeof(syn_cluster_T)); | |
176 | SYN_CLSTR(curwin->w_s)[len].scl_name = name; | |
177 | --- 5457,5462 ---- | |
178 | *************** | |
179 | *** 5476,5483 **** | |
180 | ||
181 | if (rest != NULL) | |
182 | { | |
183 | ! scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)) | |
184 | ! - SYNID_CLUSTER; | |
185 | ||
186 | for (;;) | |
187 | { | |
188 | --- 5498,5507 ---- | |
189 | ||
190 | if (rest != NULL) | |
191 | { | |
192 | ! scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); | |
193 | ! if (scl_id == 0) | |
194 | ! return; | |
195 | ! scl_id -= SYNID_CLUSTER; | |
196 | ||
197 | for (;;) | |
198 | { | |
199 | *************** | |
200 | *** 5516,5522 **** | |
201 | if (got_clstr) | |
202 | { | |
203 | redraw_curbuf_later(SOME_VALID); | |
204 | ! syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ | |
205 | } | |
206 | } | |
207 | ||
208 | --- 5540,5546 ---- | |
209 | if (got_clstr) | |
210 | { | |
211 | redraw_curbuf_later(SOME_VALID); | |
212 | ! syn_stack_free_all(curwin->w_s); /* Need to recompute all. */ | |
213 | } | |
214 | } | |
215 | ||
216 | *************** | |
217 | *** 8972,8977 **** | |
218 | --- 8996,9008 ---- | |
219 | highlight_ga.ga_growsize = 10; | |
220 | } | |
221 | ||
222 | + if (highlight_ga.ga_len >= MAX_SYNID) | |
223 | + { | |
224 | + EMSG(_("E849: Too many syntax groups")); | |
225 | + vim_free(name); | |
226 | + return 0; | |
227 | + } | |
228 | + | |
229 | /* | |
230 | * Make room for at least one other syntax_highlight entry. | |
231 | */ | |
232 | *** ../vim-7.3.147/src/version.c 2011-04-01 13:05:37.000000000 +0200 | |
233 | --- src/version.c 2011-04-01 14:26:44.000000000 +0200 | |
234 | *************** | |
235 | *** 716,717 **** | |
236 | --- 716,719 ---- | |
237 | { /* Add new patch number below this line */ | |
238 | + /**/ | |
239 | + 148, | |
240 | /**/ | |
241 | ||
242 | -- | |
243 | BLACK KNIGHT: None shall pass. | |
244 | ARTHUR: I have no quarrel with you, brave Sir knight, but I must cross | |
245 | this bridge. | |
246 | BLACK KNIGHT: Then you shall die. | |
247 | "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD | |
248 | ||
249 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
250 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
251 | \\\ an exciting new programming language -- http://www.Zimbu.org /// | |
252 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |