0
0
mirror of https://github.com/vim/vim.git synced 2025-07-24 10:45:12 -04:00

patch 8.2.1787: crash with 'incsearch' and very long line

Problem:    Crash with 'incsearch' and very long line.
Solution:   Check whether regprog becomes NULL. (closes #7063)
This commit is contained in:
Bram Moolenaar 2020-10-02 20:36:01 +02:00
parent 8a9bc95eae
commit 795aaa1e84
3 changed files with 31 additions and 1 deletions

View File

@ -759,6 +759,9 @@ searchit(
NULL, NULL NULL, NULL
#endif #endif
); );
// vim_regexec_multi() may clear "regprog"
if (regmatch.regprog == NULL)
break;
// Abort searching on an error (e.g., out of stack). // Abort searching on an error (e.g., out of stack).
if (called_emsg > called_emsg_before if (called_emsg > called_emsg_before
#ifdef FEAT_RELTIME #ifdef FEAT_RELTIME
@ -858,6 +861,9 @@ searchit(
match_ok = FALSE; match_ok = FALSE;
break; break;
} }
// vim_regexec_multi() may clear "regprog"
if (regmatch.regprog == NULL)
break;
matchpos = regmatch.startpos[0]; matchpos = regmatch.startpos[0];
endpos = regmatch.endpos[0]; endpos = regmatch.endpos[0];
# ifdef FEAT_EVAL # ifdef FEAT_EVAL
@ -972,6 +978,9 @@ searchit(
#endif #endif
break; break;
} }
// vim_regexec_multi() may clear "regprog"
if (regmatch.regprog == NULL)
break;
// Need to get the line pointer again, a // Need to get the line pointer again, a
// multi-line search may have made it invalid. // multi-line search may have made it invalid.
@ -1065,6 +1074,10 @@ searchit(
} }
at_first_line = FALSE; at_first_line = FALSE;
// vim_regexec_multi() may clear "regprog"
if (regmatch.regprog == NULL)
break;
/* /*
* Stop the search if wrapscan isn't set, "stop_lnum" is * Stop the search if wrapscan isn't set, "stop_lnum" is
* specified, after an interrupt, after a match and after looping * specified, after an interrupt, after a match and after looping
@ -2911,7 +2924,8 @@ is_zero_width(char_u *pattern, int move, pos_T *cur, int direction)
pos.lnum, regmatch.startpos[0].col, NULL, NULL); pos.lnum, regmatch.startpos[0].col, NULL, NULL);
if (nmatched != 0) if (nmatched != 0)
break; break;
} while (direction == FORWARD ? regmatch.startpos[0].col < pos.col } while (regmatch.regprog != NULL
&& direction == FORWARD ? regmatch.startpos[0].col < pos.col
: regmatch.startpos[0].col > pos.col); : regmatch.startpos[0].col > pos.col);
if (called_emsg == called_emsg_before) if (called_emsg == called_emsg_before)

View File

@ -964,6 +964,20 @@ func Test_incsearch_substitute()
call Incsearch_cleanup() call Incsearch_cleanup()
endfunc endfunc
func Test_incsearch_substitute_long_line()
new
call test_override("char_avail", 1)
set incsearch
call repeat('x', 100000)->setline(1)
call feedkeys(':s/\%c', 'xt')
redraw
call feedkeys("\<Esc>", 'xt')
call Incsearch_cleanup()
bwipe!
endfunc
" Similar to Test_incsearch_substitute() but with a screendump halfway. " Similar to Test_incsearch_substitute() but with a screendump halfway.
func Test_incsearch_substitute_dump() func Test_incsearch_substitute_dump()
CheckOption incsearch CheckOption incsearch

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1787,
/**/ /**/
1786, 1786,
/**/ /**/