comparison src/regexp.c @ 14161:7cac4646c552 v8.1.0098

patch 8.1.0098: segfault when pattern with z() is very slow commit https://github.com/vim/vim/commit/bcf9442307075bac40d44328c8bf7ea21857b138 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 23 14:21:42 2018 +0200 patch 8.1.0098: segfault when pattern with \z() is very slow 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.
author Christian Brabandt <cb@256bit.org>
date Sat, 23 Jun 2018 14:30:07 +0200
parents a90bc1e28cbb
children 42a9178374d1
comparison
equal deleted inserted replaced
14160:de4575cbbb2b 14161:7cac4646c552
365 static char_u e_unmatchedpp[] = N_("E53: Unmatched %s%%("); 365 static char_u e_unmatchedpp[] = N_("E53: Unmatched %s%%(");
366 static char_u e_unmatchedp[] = N_("E54: Unmatched %s("); 366 static char_u e_unmatchedp[] = N_("E54: Unmatched %s(");
367 static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)"); 367 static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)");
368 #ifdef FEAT_SYN_HL 368 #ifdef FEAT_SYN_HL
369 static char_u e_z_not_allowed[] = N_("E66: \\z( not allowed here"); 369 static char_u e_z_not_allowed[] = N_("E66: \\z( not allowed here");
370 static char_u e_z1_not_allowed[] = N_("E67: \\z1 et al. not allowed here"); 370 static char_u e_z1_not_allowed[] = N_("E67: \\z1 - \\z9 not allowed here");
371 #endif 371 #endif
372 static char_u e_missing_sb[] = N_("E69: Missing ] after %s%%["); 372 static char_u e_missing_sb[] = N_("E69: Missing ] after %s%%[");
373 static char_u e_empty_sb[] = N_("E70: Empty %s%%[]"); 373 static char_u e_empty_sb[] = N_("E70: Empty %s%%[]");
374 #define NOT_MULTI 0 374 #define NOT_MULTI 0
375 #define MULTI_ONE 1 375 #define MULTI_ONE 1
2137 { 2137 {
2138 c = no_Magic(getchr()); 2138 c = no_Magic(getchr());
2139 switch (c) 2139 switch (c)
2140 { 2140 {
2141 #ifdef FEAT_SYN_HL 2141 #ifdef FEAT_SYN_HL
2142 case '(': if (reg_do_extmatch != REX_SET) 2142 case '(': if ((reg_do_extmatch & REX_SET) == 0)
2143 EMSG_RET_NULL(_(e_z_not_allowed)); 2143 EMSG_RET_NULL(_(e_z_not_allowed));
2144 if (one_exactly) 2144 if (one_exactly)
2145 EMSG_ONE_RET_NULL; 2145 EMSG_ONE_RET_NULL;
2146 ret = reg(REG_ZPAREN, &flags); 2146 ret = reg(REG_ZPAREN, &flags);
2147 if (ret == NULL) 2147 if (ret == NULL)
2156 case '4': 2156 case '4':
2157 case '5': 2157 case '5':
2158 case '6': 2158 case '6':
2159 case '7': 2159 case '7':
2160 case '8': 2160 case '8':
2161 case '9': if (reg_do_extmatch != REX_USE) 2161 case '9': if ((reg_do_extmatch & REX_USE) == 0)
2162 EMSG_RET_NULL(_(e_z1_not_allowed)); 2162 EMSG_RET_NULL(_(e_z1_not_allowed));
2163 ret = regnode(ZREF + c - '0'); 2163 ret = regnode(ZREF + c - '0');
2164 re_has_z = REX_USE; 2164 re_has_z = REX_USE;
2165 break; 2165 break;
2166 #endif 2166 #endif
8330 } 8330 }
8331 #endif 8331 #endif
8332 8332
8333 /* 8333 /*
8334 * Match a regexp against multiple lines. 8334 * Match a regexp against multiple lines.
8335 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). 8335 * "rmp->regprog" must be a compiled regexp as returned by vim_regcomp().
8336 * Note: "rmp->regprog" may be freed and changed. 8336 * Note: "rmp->regprog" may be freed and changed, even set to NULL.
8337 * Uses curbuf for line count and 'iskeyword'. 8337 * Uses curbuf for line count and 'iskeyword'.
8338 * 8338 *
8339 * Return zero if there is no match. Return number of lines contained in the 8339 * Return zero if there is no match. Return number of lines contained in the
8340 * match otherwise. 8340 * match otherwise.
8341 */ 8341 */
8374 if (pat != NULL) 8374 if (pat != NULL)
8375 { 8375 {
8376 #ifdef FEAT_EVAL 8376 #ifdef FEAT_EVAL
8377 report_re_switch(pat); 8377 report_re_switch(pat);
8378 #endif 8378 #endif
8379 // checking for \z misuse was already done when compiling for NFA,
8380 // allow all here
8381 reg_do_extmatch = REX_ALL;
8379 rmp->regprog = vim_regcomp(pat, re_flags); 8382 rmp->regprog = vim_regcomp(pat, re_flags);
8383 reg_do_extmatch = 0;
8384
8380 if (rmp->regprog != NULL) 8385 if (rmp->regprog != NULL)
8381 result = rmp->regprog->engine->regexec_multi( 8386 result = rmp->regprog->engine->regexec_multi(
8382 rmp, win, buf, lnum, col, tm, timed_out); 8387 rmp, win, buf, lnum, col, tm, timed_out);
8383 vim_free(pat); 8388 vim_free(pat);
8384 } 8389 }