aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-04-05 09:00:48 +0800
committerGitHub <noreply@github.com>2022-04-05 09:00:48 +0800
commite135adcb8c4f32332ba87ea6681f41330b909e1c (patch)
tree8677bbf5a8873def93573bd0322199e745f350e3 /src
parentb08cf73be959397b5715395f1465fb76a76a6a05 (diff)
downloadrneovim-e135adcb8c4f32332ba87ea6681f41330b909e1c.tar.gz
rneovim-e135adcb8c4f32332ba87ea6681f41330b909e1c.tar.bz2
rneovim-e135adcb8c4f32332ba87ea6681f41330b909e1c.zip
vim-patch:8.2.4687: "vimgrep /%v/ *" may cause a crash (#17995)
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 vim/vim#10079) https://github.com/vim/vim/commit/e8a4c0d91f89544e4f94b7bd612b5fb780944c33
Diffstat (limited to 'src')
-rw-r--r--src/nvim/regexp.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 9a04cc428a..b61c9a2cf5 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -2504,7 +2504,8 @@ long vim_regexec_multi(
char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
p_re = BACKTRACKING_ENGINE;
- vim_regfree(rmp->regprog);
+ regprog_T *prev_prog = rmp->regprog;
+
report_re_switch(pat);
// checking for \z misuse was already done when compiling for NFA,
// allow all here
@@ -2512,7 +2513,13 @@ long vim_regexec_multi(
rmp->regprog = vim_regcomp(pat, re_flags);
reg_do_extmatch = 0;
- 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);