patch 8.2.4687: "vimgrep /\%v/ *" may cause a crash v8.2.4687
authorBram Moolenaar <Bram@vim.org>
Mon, 4 Apr 2022 17:14:34 +0000 (18:14 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 4 Apr 2022 17:14:34 +0000 (18:14 +0100)
Problem:    "vimgrep /\%v/ *" may cause a crash.
Solution:   When compiling the pattern with the old engine fails, restore the
            regprog of the new engine instead of leaving it NULL.
            (closes #10079)

src/regexp.c
src/version.c

index 110d76d042b72e9a4e145340b1adf748ddaf1b7a..c031cc9966089be088eeffb6bcc6a12e606b2785 100644 (file)
@@ -2874,9 +2874,10 @@ vim_regexec_multi(
        char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
 
        p_re = BACKTRACKING_ENGINE;
-       vim_regfree(rmp->regprog);
        if (pat != NULL)
        {
+           regprog_T *prev_prog = rmp->regprog;
+
 #ifdef FEAT_EVAL
            report_re_switch(pat);
 #endif
@@ -2889,9 +2890,16 @@ vim_regexec_multi(
 #ifdef FEAT_SYN_HL
            reg_do_extmatch = 0;
 #endif
-
-           if (rmp->regprog != NULL)
+           if (rmp->regprog == NULL)
            {
+               // Somehow compiling the pattern failed now, put back the
+               // previous one to avoid "regprog" becoming NULL.
+               rmp->regprog = prev_prog;
+           }
+           else
+           {
+               vim_regfree(prev_prog);
+
                rmp->regprog->re_in_use = TRUE;
                result = rmp->regprog->engine->regexec_multi(
                                      rmp, win, buf, lnum, col, tm, timed_out);
index fffd85f2a98e0aa31bad1bbf1c1517f74aa2e939..23dede051a9b192a5fd6e4b59c30be1c3fb54ab7 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4687,
 /**/
     4686,
 /**/