mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 00:46:30 +00:00
vim-patch:9.0.1848: [security] buffer-overflow in vim_regsub_both() (#25001)
Problem: buffer-overflow in vim_regsub_both()
Solution: Check remaining space
ced2c7394a
The change to do_sub() looks confusing. Maybe it's an overflow check?
Then the crash may not be applicable to Nvim because of different casts.
The test also looks confusing. It seems to source itself recursively.
Also don't call strlen() twice on evaluation result.
N/A patches for version.c:
vim-patch:9.0.1849: CI error on different signedness in ex_cmds.c
vim-patch:9.0.1853: CI error on different signedness in regexp.c
Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
@@ -3953,15 +3953,19 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_
|
||||
p1 = ml_get(sub_firstlnum + (linenr_T)nmatch - 1);
|
||||
nmatch_tl += nmatch - 1;
|
||||
}
|
||||
size_t copy_len = (size_t)(regmatch.startpos[0].col - copycol);
|
||||
int copy_len = regmatch.startpos[0].col - copycol;
|
||||
new_end = sub_grow_buf(&new_start, &new_start_len,
|
||||
(colnr_T)strlen(p1) - regmatch.endpos[0].col
|
||||
+ (colnr_T)copy_len + sublen + 1);
|
||||
+ copy_len + sublen + 1);
|
||||
|
||||
// copy the text up to the part that matched
|
||||
memmove(new_end, sub_firstline + copycol, copy_len);
|
||||
memmove(new_end, sub_firstline + copycol, (size_t)copy_len);
|
||||
new_end += copy_len;
|
||||
|
||||
if (new_start_len - copy_len < sublen) {
|
||||
sublen = new_start_len - copy_len - 1;
|
||||
}
|
||||
|
||||
// Finally, at this point we can know where the match actually will
|
||||
// start in the new text
|
||||
int start_col = (int)(new_end - new_start);
|
||||
|
Reference in New Issue
Block a user