summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-15 14:50:12 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-15 14:50:12 +0100
commitb62dc5e7825bc195efe3041d5b3a9f1528359e1c (patch)
treea0469ca3fc215cbb3aed246d121442853ced3f2b /src
parentdd41037552c1be3548d2ce34bb1c889f14edb553 (diff)
patch 8.2.4959: using NULL regexp programv8.2.4959
Problem: Using NULL regexp program. Solution: Check for regexp program becoming NULL in more places.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c35
-rw-r--r--src/testdir/test_buffer.vim6
-rw-r--r--src/version.c2
3 files changed, 30 insertions, 13 deletions
diff --git a/src/buffer.c b/src/buffer.c
index dfdb0c430d..3234138aeb 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2642,13 +2642,15 @@ buflist_findpat(
if (*p == '^' && !(attempt & 1)) // add/remove '^'
++p;
regmatch.regprog = vim_regcomp(p, magic_isset() ? RE_MAGIC : 0);
- if (regmatch.regprog == NULL)
- {
- vim_free(pat);
- return -1;
- }
FOR_ALL_BUFS_FROM_LAST(buf)
+ {
+ if (regmatch.regprog == NULL)
+ {
+ // invalid pattern, possibly after switching engine
+ vim_free(pat);
+ return -1;
+ }
if (buf->b_p_bl == find_listed
#ifdef FEAT_DIFF
&& (!diffmode || diff_mode_buf(buf))
@@ -2674,6 +2676,7 @@ buflist_findpat(
}
match = buf->b_fnum; // remember first match
}
+ }
vim_regfree(regmatch.regprog);
if (match >= 0) // found one match
@@ -2766,12 +2769,6 @@ ExpandBufnames(
if (attempt > 0 && patc == pat)
break; // there was no anchor, no need to try again
regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC);
- if (regmatch.regprog == NULL)
- {
- if (patc != pat)
- vim_free(patc);
- return FAIL;
- }
}
// round == 1: Count the matches.
@@ -2792,7 +2789,16 @@ ExpandBufnames(
#endif
if (!fuzzy)
+ {
+ if (regmatch.regprog == NULL)
+ {
+ // invalid pattern, possibly after recompiling
+ if (patc != pat)
+ vim_free(patc);
+ return FAIL;
+ }
p = buflist_match(&regmatch, buf, p_wic);
+ }
else
{
p = NULL;
@@ -2921,6 +2927,7 @@ ExpandBufnames(
/*
* Check for a match on the file name for buffer "buf" with regprog "prog".
+ * Note that rmp->regprog may become NULL when switching regexp engine.
*/
static char_u *
buflist_match(
@@ -2939,7 +2946,8 @@ buflist_match(
}
/*
- * Try matching the regexp in "prog" with file name "name".
+ * Try matching the regexp in "rmp->regprog" with file name "name".
+ * Note that rmp->regprog may become NULL when switching regexp engine.
* Return "name" when there is a match, NULL when not.
*/
static char_u *
@@ -2951,7 +2959,8 @@ fname_match(
char_u *match = NULL;
char_u *p;
- if (name != NULL)
+ // extra check for valid arguments
+ if (name != NULL && rmp->regprog != NULL)
{
// Ignore case when 'fileignorecase' or the argument is set.
rmp->rm_ic = p_fic || ignore_case;
diff --git a/src/testdir/test_buffer.vim b/src/testdir/test_buffer.vim
index 55ef0fda76..4dcfd2d8f7 100644
--- a/src/testdir/test_buffer.vim
+++ b/src/testdir/test_buffer.vim
@@ -419,6 +419,12 @@ func Test_buf_pattern_invalid()
vsplit 00000000000000000000000000
silent! buf [0--]\&\zs*\zs*e
bwipe!
+
+ " similar case with different code path
+ split 0
+ edit ΓΏ
+ silent! buf [0--]\&\zs*\zs*0
+ bwipe!
endfunc
" Test for the 'maxmem' and 'maxmemtot' options
diff --git a/src/version.c b/src/version.c
index 856922e1f5..dca2f92092 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4959,
+/**/
4958,
/**/
4957,