Skip to content

Commit b13089c

Browse files
authored
Merge pull request neovim#18522 from zeertzjq/vim-8.2.4901
vim-patch:8.2.{4901,4938}: NULL pointer access when using invalid pattern
2 parents 96a125b + 6f52bc5 commit b13089c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/nvim/buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case)
23662366
{
23672367
// First try the short file name, then the long file name.
23682368
char_u *match = fname_match(rmp, buf->b_sfname, ignore_case);
2369-
if (match == NULL) {
2369+
if (match == NULL && rmp->regprog != NULL) {
23702370
match = fname_match(rmp, buf->b_ffname, ignore_case);
23712371
}
23722372
return match;
@@ -2387,7 +2387,7 @@ static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case)
23872387
rmp->rm_ic = p_fic || ignore_case;
23882388
if (vim_regexec(rmp, name, (colnr_T)0)) {
23892389
match = name;
2390-
} else {
2390+
} else if (rmp->regprog != NULL) {
23912391
// Replace $(HOME) with '~' and try matching again.
23922392
p = home_replace_save(NULL, name);
23932393
if (vim_regexec(rmp, p, (colnr_T)0)) {

src/nvim/testdir/test_buffer.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,15 @@ func Test_buffer_scheme()
6161
set shellslash&
6262
endfunc
6363

64+
" this was using a NULL pointer after failing to use the pattern
65+
func Test_buf_pattern_invalid()
66+
vsplit 0000000
67+
silent! buf [0--]\&\zs*\zs*e
68+
bwipe!
69+
70+
vsplit 00000000000000000000000000
71+
silent! buf [0--]\&\zs*\zs*e
72+
bwipe!
73+
endfunc
74+
6475
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)