From c0f10d3fe018990b68cfa47bd84693449100f449 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:09:29 +0800 Subject: vim-patch:9.0.0783: ":!" doesn't do anything but does update the previous command Problem: ":!" doesn't do anything but does update the previous command. Solution: Do not have ":!" change the previous command. (Martin Tournoij, closes vim/vim#11372) https://github.com/vim/vim/commit/8107a2a8af80a53a61734b600539c5beb4782991 Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a1b43113a6..cc8c4aeca8 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1012,6 +1012,12 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } } while (trailarg != NULL); + // Don't do anything if there is no command as there isn't really anything + // useful in running "sh -c ''". Avoids changing "prevcmd". + if (strlen(newcmd) == 0) { + return; + } + xfree(prevcmd); prevcmd = newcmd; -- cgit From 5b77dde8dd281b1db1f503d9b270c3697f88bd65 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:22:16 +0800 Subject: vim-patch:9.0.0785: memory leak with empty shell command Problem: Memory leak with empty shell command. Solution: Free the allocated memory when bailing out. https://github.com/vim/vim/commit/9652249a2d02318a28a63a7b5711f25652e8f969 Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index cc8c4aeca8..015f651872 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1015,6 +1015,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out // Don't do anything if there is no command as there isn't really anything // useful in running "sh -c ''". Avoids changing "prevcmd". if (strlen(newcmd) == 0) { + xfree(newcmd); return; } -- cgit From 187ba3efce4acc197ce6cc9559a905eec97bacbe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:23:09 +0800 Subject: vim-patch:9.0.0815 https://github.com/vim/vim/commit/9c50eeb40117413bf59a9da904c8d0921ed0a6e6 Co-authored-by: Martin Tournoij --- src/nvim/ex_cmds.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 015f651872..f7447cda1b 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -988,6 +988,8 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } if (ins_prevcmd) { STRCAT(t, prevcmd); + } else { + xfree(t); } p = t + strlen(t); STRCAT(t, trailarg); @@ -1012,16 +1014,12 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } } while (trailarg != NULL); - // Don't do anything if there is no command as there isn't really anything - // useful in running "sh -c ''". Avoids changing "prevcmd". - if (strlen(newcmd) == 0) { - xfree(newcmd); - return; + // Don't clear "prevcmd" if there is no command to run. + if (strlen(newcmd) > 0) { + xfree(prevcmd); + prevcmd = newcmd; } - xfree(prevcmd); - prevcmd = newcmd; - if (bangredo) { // put cmd in redo buffer for ! command // If % or # appears in the command, it must have been escaped. // Reescape them, so that redoing them does not substitute them by the -- cgit From a1e0f6c07fc575dfac4cd4c0d8c395b8d3f1a4f4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:28:00 +0800 Subject: vim-patch:9.0.0817 https://github.com/vim/vim/commit/fb0cf2357e0c85bbfd9f9178705ad8d77b6b3b4e Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index f7447cda1b..db9cf94cba 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -988,8 +988,6 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } if (ins_prevcmd) { STRCAT(t, prevcmd); - } else { - xfree(t); } p = t + strlen(t); STRCAT(t, trailarg); -- cgit From 2a94dcf0c592464222c87f5606799ca51a0b9c07 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:30:08 +0800 Subject: vim-patch:9.0.0820: memory leak with empty shell command Problem: Memory leak with empty shell command. Solution: Free the empty string. https://github.com/vim/vim/commit/03d6e6f42b0deeb02d52c8a48c14abe431370c1c Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index db9cf94cba..55dbe17ad6 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1012,10 +1012,13 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } } while (trailarg != NULL); - // Don't clear "prevcmd" if there is no command to run. + // Only set "prevcmd" if there is a command to run, otherwise keep te one + // we have. if (strlen(newcmd) > 0) { xfree(prevcmd); prevcmd = newcmd; + } else { + free_newcmd = true; } if (bangredo) { // put cmd in redo buffer for ! command @@ -1031,6 +1034,9 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } // Add quotes around the command, for shells that need them. if (*p_shq != NUL) { + if (free_newcmd) { + xfree(newcmd); + } newcmd = xmalloc(strlen(prevcmd) + 2 * strlen(p_shq) + 1); STRCPY(newcmd, p_shq); STRCAT(newcmd, prevcmd); -- cgit From 9180c18c462a4945657899b732189da6f2ea2eaf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:31:40 +0800 Subject: vim-patch:9.0.0864: crash when using "!!" without a previous shell command Problem: Crash when using "!!" without a previous shell command. Solution: Check "prevcmd" is not NULL. (closes vim/vim#11487) https://github.com/vim/vim/commit/6600447c7b0a1be3a64d07a318bacdfaae0cac4b Co-authored-by: Bram Moolenaar --- src/nvim/eval/userfunc.c | 2 +- src/nvim/ex_cmds.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index e138c50b6a..63d5f94f11 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -3207,7 +3207,7 @@ static int ex_defer_inner(char *name, char **arg, const partial_T *const partial } /// Return true if currently inside a function call. -/// Give an error message and return FALSE when not. +/// Give an error message and return false when not. bool can_add_defer(void) { if (get_current_funccal() == NULL) { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 55dbe17ad6..b75ff45843 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -933,6 +933,17 @@ void free_prev_shellcmd(void) #endif +/// Check that "prevcmd" is not NULL. If it is NULL then give an error message +/// and return false. +static int prevcmd_is_set(void) +{ + if (prevcmd == NULL) { + emsg(_(e_noprev)); + return false; + } + return true; +} + /// Handle the ":!cmd" command. Also for ":r !cmd" and ":w !cmd" /// Bangs in the argument are replaced with the previously entered command. /// Remember the argument. @@ -974,8 +985,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out len += strlen(newcmd); } if (ins_prevcmd) { - if (prevcmd == NULL) { - emsg(_(e_noprev)); + if (!prevcmd_is_set()) { xfree(newcmd); return; } @@ -1022,6 +1032,10 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } if (bangredo) { // put cmd in redo buffer for ! command + if (!prevcmd_is_set()) { + goto theend; + } + // If % or # appears in the command, it must have been escaped. // Reescape them, so that redoing them does not substitute them by the // buffername. @@ -1059,6 +1073,8 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out do_filter(line1, line2, eap, newcmd, do_in, do_out); apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, false, curbuf); } + +theend: if (free_newcmd) { xfree(newcmd); } -- cgit