mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
vim-patch:8.2.4977: memory access error when substitute expression changes window
Problem: Memory access error when substitute expression changes window.
Solution: Disallow changing window in substitute expression.
e2bd8600b8
"textwinlock" was renamed back to "textlock" in patch 8.2.5029.
This commit is contained in:
@@ -4069,11 +4069,16 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
|
|||||||
// Save flags for recursion. They can change for e.g.
|
// Save flags for recursion. They can change for e.g.
|
||||||
// :s/^/\=execute("s#^##gn")
|
// :s/^/\=execute("s#^##gn")
|
||||||
subflags_T subflags_save = subflags;
|
subflags_T subflags_save = subflags;
|
||||||
|
|
||||||
|
// Disallow changing text or switching window in an expression.
|
||||||
|
textlock++;
|
||||||
// get length of substitution part
|
// get length of substitution part
|
||||||
sublen = vim_regsub_multi(®match,
|
sublen = vim_regsub_multi(®match,
|
||||||
sub_firstlnum - regmatch.startpos[0].lnum,
|
sub_firstlnum - regmatch.startpos[0].lnum,
|
||||||
(char_u *)sub, (char_u *)sub_firstline, 0,
|
(char_u *)sub, (char_u *)sub_firstline, 0,
|
||||||
REGSUB_BACKSLASH | (p_magic ? REGSUB_MAGIC : 0));
|
REGSUB_BACKSLASH | (p_magic ? REGSUB_MAGIC : 0));
|
||||||
|
textlock--;
|
||||||
|
|
||||||
// If getting the substitute string caused an error, don't do
|
// If getting the substitute string caused an error, don't do
|
||||||
// the replacement.
|
// the replacement.
|
||||||
// Don't keep flags set by a recursive call
|
// Don't keep flags set by a recursive call
|
||||||
@@ -4111,10 +4116,12 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
|
|||||||
int start_col = new_end - new_start;
|
int start_col = new_end - new_start;
|
||||||
current_match.start.col = start_col;
|
current_match.start.col = start_col;
|
||||||
|
|
||||||
|
textlock++;
|
||||||
(void)vim_regsub_multi(®match,
|
(void)vim_regsub_multi(®match,
|
||||||
sub_firstlnum - regmatch.startpos[0].lnum,
|
sub_firstlnum - regmatch.startpos[0].lnum,
|
||||||
(char_u *)sub, (char_u *)new_end, sublen,
|
(char_u *)sub, (char_u *)new_end, sublen,
|
||||||
REGSUB_COPY | REGSUB_BACKSLASH | (p_magic ? REGSUB_MAGIC : 0));
|
REGSUB_COPY | REGSUB_BACKSLASH | (p_magic ? REGSUB_MAGIC : 0));
|
||||||
|
textlock--;
|
||||||
sub_nsubs++;
|
sub_nsubs++;
|
||||||
did_sub = true;
|
did_sub = true;
|
||||||
|
|
||||||
|
@@ -838,6 +838,19 @@ func Test_using_old_sub()
|
|||||||
set nocompatible
|
set nocompatible
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" This was switching windows in between computing the length and using it.
|
||||||
|
func Test_sub_change_window()
|
||||||
|
silent! lfile
|
||||||
|
sil! norm o0000000000000000000000000000000000000000000000000000
|
||||||
|
func Repl()
|
||||||
|
lopen
|
||||||
|
endfunc
|
||||||
|
silent! s/\%')/\=Repl()
|
||||||
|
bwipe!
|
||||||
|
bwipe!
|
||||||
|
delfunc Repl
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for the 2-letter and 3-letter :substitute commands
|
" Test for the 2-letter and 3-letter :substitute commands
|
||||||
func Test_substitute_short_cmd()
|
func Test_substitute_short_cmd()
|
||||||
new
|
new
|
||||||
|
Reference in New Issue
Block a user