aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_docmd.c
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2022-03-12 08:25:28 +0000
committerGitHub <noreply@github.com>2022-03-12 08:25:28 +0000
commitab456bc304965d83585cd248284cb36c96927457 (patch)
treeb01391cee9c3e971072ccb4d27825b61fb10fbbd /src/nvim/ex_docmd.c
parent08d9d74fd91adb29e1f71a48a21df955568cdfcb (diff)
downloadrneovim-ab456bc304965d83585cd248284cb36c96927457.tar.gz
rneovim-ab456bc304965d83585cd248284cb36c96927457.tar.bz2
rneovim-ab456bc304965d83585cd248284cb36c96927457.zip
vim-patch:8.2.3779: using freed memory when defining a user command recursively (#17688)
Problem: Using freed memory when defining a user command from a user command. Solution: Do not use the command pointer after executing the command. (closes vim/vim#9318) https://github.com/vim/vim/commit/205f29c3e9b895dbaa4f738046da455a93c3812a
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r--src/nvim/ex_docmd.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index a140d76858..63dc1e539e 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -6230,7 +6230,6 @@ static void do_ucmd(exarg_T *eap)
size_t split_len = 0;
char_u *split_buf = NULL;
ucmd_T *cmd;
- const sctx_T save_current_sctx = current_sctx;
if (eap->cmdidx == CMD_USER) {
cmd = USER_CMD(eap->useridx);
@@ -6320,12 +6319,19 @@ static void do_ucmd(exarg_T *eap)
buf = xmalloc(totlen + 1);
}
+ sctx_T save_current_sctx;
+ bool restore_current_sctx = false;
if ((cmd->uc_argt & EX_KEEPSCRIPT) == 0) {
+ restore_current_sctx = true;
+ save_current_sctx = current_sctx;
current_sctx.sc_sid = cmd->uc_script_ctx.sc_sid;
}
(void)do_cmdline(buf, eap->getline, eap->cookie,
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED);
- if ((cmd->uc_argt & EX_KEEPSCRIPT) == 0) {
+
+ // Careful: Do not use "cmd" here, it may have become invalid if a user
+ // command was added.
+ if (restore_current_sctx) {
current_sctx = save_current_sctx;
}
xfree(buf);