mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
vim-patch:9.0.1145: invalid memory access with recursive substitute expression (#23132)
Problem: Invalid memory access with recursive substitute expression.
Solution: Check the return value of vim_regsub().
3ac1d97a1d
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -8375,6 +8375,10 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, const char
|
|||||||
// - The substituted text.
|
// - The substituted text.
|
||||||
// - The text after the match.
|
// - The text after the match.
|
||||||
sublen = vim_regsub(®match, sub, expr, tail, 0, REGSUB_MAGIC);
|
sublen = vim_regsub(®match, sub, expr, tail, 0, REGSUB_MAGIC);
|
||||||
|
if (sublen <= 0) {
|
||||||
|
ga_clear(&ga);
|
||||||
|
break;
|
||||||
|
}
|
||||||
ga_grow(&ga, (int)((end - tail) + sublen -
|
ga_grow(&ga, (int)((end - tail) + sublen -
|
||||||
(regmatch.endp[0] - regmatch.startp[0])));
|
(regmatch.endp[0] - regmatch.startp[0])));
|
||||||
|
|
||||||
|
@@ -1109,6 +1109,22 @@ func Test_sub_expr_goto_other_file()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_recursive_expr_substitute()
|
||||||
|
" this was reading invalid memory
|
||||||
|
let lines =<< trim END
|
||||||
|
func Repl(g, n)
|
||||||
|
s
|
||||||
|
r%:s000
|
||||||
|
endfunc
|
||||||
|
next 0
|
||||||
|
let caught = 0
|
||||||
|
s/\%')/\=Repl(0, 0)
|
||||||
|
qall!
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XexprSubst', 'D')
|
||||||
|
call RunVim([], [], '--clean -S XexprSubst')
|
||||||
|
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