From 5a752c97d5294f4a69613db71adf9beb6a8f8790 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 29 Nov 2018 01:51:26 +0100 Subject: vim-patch:8.1.0098: segfault when pattern with \z() is very slow (#9283) 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. https://github.com/vim/vim/commit/bcf9442307075bac40d44328c8bf7ea21857b138 closes #8788 --- src/nvim/regexp_nfa.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/nvim/regexp_nfa.c') diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index fe18cb4389..08ef7da9c1 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -1367,20 +1367,23 @@ static int nfa_regatom(void) case '7': case '8': case '9': - /* \z1...\z9 */ - if (reg_do_extmatch != REX_USE) + // \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 * change when \z1 .. \z9 matches or not. */ re_has_z = REX_USE; break; case '(': - /* \z( */ - if (reg_do_extmatch != REX_SET) + // \z( + if (reg_do_extmatch != REX_SET) { EMSG_RET_FAIL(_(e_z_not_allowed)); - if (nfa_reg(REG_ZPAREN) == FAIL) - return FAIL; /* cascaded error */ + } + if (nfa_reg(REG_ZPAREN) == FAIL) { + return FAIL; // cascaded error + } re_has_z = REX_SET; break; default: @@ -5052,10 +5055,11 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, /* swap lists */ thislist = &list[flag]; nextlist = &list[flag ^= 1]; - nextlist->n = 0; /* clear nextlist */ - nextlist->has_pim = FALSE; - ++nfa_listid; - if (prog->re_engine == AUTOMATIC_ENGINE && nfa_listid >= NFA_MAX_STATES) { + 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; goto theend; -- cgit