changeset 28323:82f34ca7b3b7 v8.2.4687

patch 8.2.4687: "vimgrep /%v/ *" may cause a crash Commit: https://github.com/vim/vim/commit/e8a4c0d91f89544e4f94b7bd612b5fb780944c33 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 4 18:14:34 2022 +0100 patch 8.2.4687: "vimgrep /\%v/ *" may cause a crash 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)
author Bram Moolenaar <Bram@vim.org>
date Mon, 04 Apr 2022 19:15:03 +0200
parents b85b114e3f57
children 8b0d6c2190c0
files src/regexp.c src/version.c
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -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)
+	    {
+		// 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);
 
-	    if (rmp->regprog != NULL)
-	    {
 		rmp->regprog->re_in_use = TRUE;
 		result = rmp->regprog->engine->regexec_multi(
 				      rmp, win, buf, lnum, col, tm, timed_out);
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4687,
+/**/
     4686,
 /**/
     4685,