summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0098
blob: f05b1645290602f0dc9b4acfc2aa53d22d163b1a (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0098
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0098
Problem:    Segfault when pattern with \z() is very slow.
Solution:   Check for NULL regprog.  Add "nfa_fail" to test_override() to be
            able to test this.  Fix that 'searchhl' resets called_emsg.
Files:	    src/syntax.c, runtime/doc/eval.txt, src/evalfunc.c, src/vim.h,
            src/testdir/test_syntax.vim, src/globals.h, src/screen.c,
            src/regexp.c, src/regexp_nfa.c


*** ../vim-8.1.0097/src/syntax.c	2018-05-20 13:35:40.193163458 +0200
--- src/syntax.c	2018-06-23 13:47:27.294238648 +0200
***************
*** 3327,3332 ****
--- 3327,3338 ----
  	profile_start(&pt);
  #endif
  
+     if (rmp->regprog == NULL)
+ 	// This can happen if a previous call to vim_regexec_multi() tried to
+ 	// use the NFA engine, which resulted in NFA_TOO_EXPENSIVE, and
+ 	// compiling the pattern with the other engine fails.
+ 	return FALSE;
+ 
      rmp->rmm_maxcol = syn_buf->b_p_smc;
      r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col,
  #ifdef FEAT_RELTIME
*** ../vim-8.1.0097/runtime/doc/eval.txt	2018-06-20 22:37:52.658911284 +0200
--- runtime/doc/eval.txt	2018-06-23 13:27:43.863676347 +0200
***************
*** 8694,8699 ****
--- 8694,8701 ----
  		redraw       disable the redrawing() function
  		char_avail   disable the char_avail() function
  		starting     reset the "starting" variable, see below
+ 		nfa_fail     makes the NFA regexp engine fail to force a
+ 			     fallback to the old engine
  		ALL	     clear all overrides ({val} is not used)
  
  		"starting" is to be used when a test should behave like
*** ../vim-8.1.0097/src/evalfunc.c	2018-06-20 22:37:52.654911306 +0200
--- src/evalfunc.c	2018-06-23 13:29:32.603042364 +0200
***************
*** 13090,13099 ****
--- 13090,13102 ----
  		save_starting = -1;
  	    }
  	}
+ 	else if (STRCMP(name, (char_u *)"nfa_fail") == 0)
+ 	    nfa_fail_for_testing = val;
  	else if (STRCMP(name, (char_u *)"ALL") == 0)
  	{
  	    disable_char_avail_for_testing = FALSE;
  	    disable_redraw_for_testing = FALSE;
+ 	    nfa_fail_for_testing = FALSE;
  	    if (save_starting >= 0)
  	    {
  		starting = save_starting;
*** ../vim-8.1.0097/src/vim.h	2018-04-30 15:12:48.000000000 +0200
--- src/vim.h	2018-06-23 14:06:57.244449803 +0200
***************
*** 1013,1018 ****
--- 1013,1019 ----
  /* values for reg_do_extmatch */
  # define REX_SET	1	/* to allow \z\(...\), */
  # define REX_USE	2	/* to allow \z\1 et al. */
+ # define REX_ALL	(REX_SET | REX_USE)
  #endif
  
  /* Return values for fullpathcmp() */
*** ../vim-8.1.0097/src/testdir/test_syntax.vim	2018-02-24 19:33:19.000000000 +0100
--- src/testdir/test_syntax.vim	2018-06-23 14:11:40.474945470 +0200
***************
*** 562,564 ****
--- 562,576 ----
    let $COLORFGBG = ''
    call delete('Xtest.c')
  endfun
+ 
+ " Using \z() in a region with NFA failing should not crash.
+ func Test_syn_wrong_z_one()
+   new
+   call setline(1, ['just some text', 'with foo and bar to match with'])
+   syn region FooBar start="foo\z(.*\)bar" end="\z1"
+   call test_override("nfa_fail", 1)
+   redraw!
+   redraw!
+   call test_override("ALL", 0)
+   bwipe!
+ endfunc
*** ../vim-8.1.0097/src/globals.h	2018-06-19 17:49:20.296015375 +0200
--- src/globals.h	2018-06-23 13:30:00.290880945 +0200
***************
*** 1634,1639 ****
--- 1634,1640 ----
  /* flags set by test_override() */
  EXTERN int  disable_char_avail_for_testing INIT(= 0);
  EXTERN int  disable_redraw_for_testing INIT(= 0);
+ EXTERN int  nfa_fail_for_testing INIT(= 0);
  
  EXTERN int  in_free_unref_items INIT(= FALSE);
  #endif
*** ../vim-8.1.0097/src/screen.c	2018-06-17 16:23:29.341140642 +0200
--- src/screen.c	2018-06-23 14:02:46.329754550 +0200
***************
*** 7868,7873 ****
--- 7868,7874 ----
      linenr_T	l;
      colnr_T	matchcol;
      long	nmatched;
+     int		save_called_emsg = called_emsg;
  
      if (shl->lnum != 0)
      {
***************
*** 7986,7991 ****
--- 7987,7995 ----
  	    break;			/* useful match found */
  	}
      }
+ 
+     // Restore called_emsg for assert_fails().
+     called_emsg = save_called_emsg;
  }
  
  /*
*** ../vim-8.1.0097/src/regexp.c	2018-02-13 16:28:11.000000000 +0100
--- src/regexp.c	2018-06-23 14:09:21.727692568 +0200
***************
*** 367,373 ****
  static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)");
  #ifdef FEAT_SYN_HL
  static char_u e_z_not_allowed[] = N_("E66: \\z( not allowed here");
! static char_u e_z1_not_allowed[] = N_("E67: \\z1 et al. not allowed here");
  #endif
  static char_u e_missing_sb[] = N_("E69: Missing ] after %s%%[");
  static char_u e_empty_sb[]  = N_("E70: Empty %s%%[]");
--- 367,373 ----
  static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)");
  #ifdef FEAT_SYN_HL
  static char_u e_z_not_allowed[] = N_("E66: \\z( not allowed here");
! static char_u e_z1_not_allowed[] = N_("E67: \\z1 - \\z9 not allowed here");
  #endif
  static char_u e_missing_sb[] = N_("E69: Missing ] after %s%%[");
  static char_u e_empty_sb[]  = N_("E70: Empty %s%%[]");
***************
*** 2139,2145 ****
  	    switch (c)
  	    {
  #ifdef FEAT_SYN_HL
! 		case '(': if (reg_do_extmatch != REX_SET)
  			      EMSG_RET_NULL(_(e_z_not_allowed));
  			  if (one_exactly)
  			      EMSG_ONE_RET_NULL;
--- 2139,2145 ----
  	    switch (c)
  	    {
  #ifdef FEAT_SYN_HL
! 		case '(': if ((reg_do_extmatch & REX_SET) == 0)
  			      EMSG_RET_NULL(_(e_z_not_allowed));
  			  if (one_exactly)
  			      EMSG_ONE_RET_NULL;
***************
*** 2158,2164 ****
  		case '6':
  		case '7':
  		case '8':
! 		case '9': if (reg_do_extmatch != REX_USE)
  			      EMSG_RET_NULL(_(e_z1_not_allowed));
  			  ret = regnode(ZREF + c - '0');
  			  re_has_z = REX_USE;
--- 2158,2164 ----
  		case '6':
  		case '7':
  		case '8':
! 		case '9': if ((reg_do_extmatch & REX_USE) == 0)
  			      EMSG_RET_NULL(_(e_z1_not_allowed));
  			  ret = regnode(ZREF + c - '0');
  			  re_has_z = REX_USE;
***************
*** 8332,8339 ****
  
  /*
   * Match a regexp against multiple lines.
!  * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
!  * Note: "rmp->regprog" may be freed and changed.
   * Uses curbuf for line count and 'iskeyword'.
   *
   * Return zero if there is no match.  Return number of lines contained in the
--- 8332,8339 ----
  
  /*
   * Match a regexp against multiple lines.
!  * "rmp->regprog" must be a compiled regexp as returned by vim_regcomp().
!  * Note: "rmp->regprog" may be freed and changed, even set to NULL.
   * Uses curbuf for line count and 'iskeyword'.
   *
   * Return zero if there is no match.  Return number of lines contained in the
***************
*** 8376,8382 ****
--- 8376,8387 ----
  #ifdef FEAT_EVAL
  	    report_re_switch(pat);
  #endif
+ 	    // checking for \z misuse was already done when compiling for NFA,
+ 	    // allow all here
+ 	    reg_do_extmatch = REX_ALL;
  	    rmp->regprog = vim_regcomp(pat, re_flags);
+ 	    reg_do_extmatch = 0;
+ 
  	    if (rmp->regprog != NULL)
  		result = rmp->regprog->engine->regexec_multi(
  				      rmp, win, buf, lnum, col, tm, timed_out);
*** ../vim-8.1.0097/src/regexp_nfa.c	2018-06-22 21:42:26.743455036 +0200
--- src/regexp_nfa.c	2018-06-23 14:08:50.071858765 +0200
***************
*** 1482,1488 ****
  		case '8':
  		case '9':
  		    /* \z1...\z9 */
! 		    if (reg_do_extmatch != REX_USE)
  			EMSG_RET_FAIL(_(e_z1_not_allowed));
  		    EMIT(NFA_ZREF1 + (no_Magic(c) - '1'));
  		    /* No need to set nfa_has_backref, the sub-matches don't
--- 1482,1488 ----
  		case '8':
  		case '9':
  		    /* \z1...\z9 */
! 		    if ((reg_do_extmatch & REX_USE) == 0)
  			EMSG_RET_FAIL(_(e_z1_not_allowed));
  		    EMIT(NFA_ZREF1 + (no_Magic(c) - '1'));
  		    /* No need to set nfa_has_backref, the sub-matches don't
***************
*** 1491,1497 ****
  		    break;
  		case '(':
  		    /* \z(  */
! 		    if (reg_do_extmatch != REX_SET)
  			EMSG_RET_FAIL(_(e_z_not_allowed));
  		    if (nfa_reg(REG_ZPAREN) == FAIL)
  			return FAIL;	    /* cascaded error */
--- 1491,1497 ----
  		    break;
  		case '(':
  		    /* \z(  */
! 		    if ((reg_do_extmatch & REX_SET) == 0)
  			EMSG_RET_FAIL(_(e_z_not_allowed));
  		    if (nfa_reg(REG_ZPAREN) == FAIL)
  			return FAIL;	    /* cascaded error */
***************
*** 5692,5698 ****
  	nextlist->n = 0;	    /* clear nextlist */
  	nextlist->has_pim = FALSE;
  	++nfa_listid;
! 	if (prog->re_engine == AUTOMATIC_ENGINE && nfa_listid >= NFA_MAX_STATES)
  	{
  	    /* too many states, retry with old engine */
  	    nfa_match = NFA_TOO_EXPENSIVE;
--- 5692,5699 ----
  	nextlist->n = 0;	    /* clear nextlist */
  	nextlist->has_pim = FALSE;
  	++nfa_listid;
! 	if (prog->re_engine == AUTOMATIC_ENGINE
! 		&& (nfa_listid >= NFA_MAX_STATES || nfa_fail_for_testing))
  	{
  	    /* too many states, retry with old engine */
  	    nfa_match = NFA_TOO_EXPENSIVE;
*** ../vim-8.1.0097/src/version.c	2018-06-22 21:42:26.747455046 +0200
--- src/version.c	2018-06-23 13:28:43.939326081 +0200
***************
*** 763,764 ****
--- 763,766 ----
  {   /* Add new patch number below this line */
+ /**/
+     98,
  /**/

-- 
I AM THANKFUL...
...for all the complaining I hear about the government
because it means we have freedom of speech.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///