aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/regexp.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-21 16:00:45 +0800
committerGitHub <noreply@github.com>2022-07-21 16:00:45 +0800
commit6a7d00469bd64e8fe63468b5c1643087432709e9 (patch)
treec24e6965b63350916f74e2e18982bbad66e2306d /src/nvim/regexp.c
parent1f1863ed54355c314a5016560809e65c3fb0cb79 (diff)
downloadrneovim-6a7d00469bd64e8fe63468b5c1643087432709e9.tar.gz
rneovim-6a7d00469bd64e8fe63468b5c1643087432709e9.tar.bz2
rneovim-6a7d00469bd64e8fe63468b5c1643087432709e9.zip
vim-patch:9.0.0047: using freed memory with recursive substitute (#19457)
Problem: Using freed memory with recursive substitute. Solution: Always make a copy for reg_prev_sub. https://github.com/vim/vim/commit/32acf1f1a72ebb9d8942b9c9d80023bf1bb668ea
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r--src/nvim/regexp.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 4c49d30819..2e43e388cd 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -1587,12 +1587,10 @@ char_u *regtilde(char_u *source, int magic, bool preview)
// Only change reg_prev_sub when not previewing.
if (!preview) {
+ // Store a copy of newsub in reg_prev_sub. It is always allocated,
+ // because recursive calls may make the returned string invalid.
xfree(reg_prev_sub);
- if (newsub != source) { // newsub was allocated, just keep it
- reg_prev_sub = newsub;
- } else { // no ~ found, need to save newsub
- reg_prev_sub = vim_strsave(newsub);
- }
+ reg_prev_sub = vim_strsave(newsub);
}
return newsub;