From dc2745e9eac08d4537c409a8700c37bc9d42d6de Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 27 Jul 2022 15:42:56 +0100 Subject: refactor(cmd): unify execute_cmd with do_one_cmd --- src/nvim/api/command.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index 33efa6b326..5ab0beec9d 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -505,6 +505,11 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error OBJ_TO_BOOL(cmdinfo.magic.file, magic.file, ea.argt & EX_XFILE, "'magic.file'"); OBJ_TO_BOOL(cmdinfo.magic.bar, magic.bar, ea.argt & EX_TRLBAR, "'magic.bar'"); + if (cmdinfo.magic.file) { + ea.argt |= EX_XFILE; + } else { + ea.argt &= ~EX_XFILE; + } } else { cmdinfo.magic.file = ea.argt & EX_XFILE; cmdinfo.magic.bar = ea.argt & EX_TRLBAR; -- cgit From 3df8d9b8c56a7f0af0f7590b11831bd96ead92f1 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Wed, 3 Aug 2022 14:41:17 +0200 Subject: feat(lua): print source locations of lua callbacks (#19597) Co-authored-by: ii14 --- src/nvim/api/command.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index 5ab0beec9d..04242932c9 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -944,7 +944,7 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, cmd_addr_T addr_type_arg = ADDR_NONE; int compl = EXPAND_NOTHING; char *compl_arg = NULL; - char *rep = NULL; + const char *rep = NULL; LuaRef luaref = LUA_NOREF; LuaRef compl_luaref = LUA_NOREF; LuaRef preview_luaref = LUA_NOREF; @@ -1116,8 +1116,7 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, if (opts->desc.type == kObjectTypeString) { rep = opts->desc.data.string.data; } else { - snprintf((char *)IObuff, IOSIZE, "", luaref); - rep = (char *)IObuff; + rep = ""; } break; case kObjectTypeString: -- cgit From a308f53525d77e26c372af385f6f4d89638b3962 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 6 Aug 2022 06:22:01 +0800 Subject: fix(api): fix nvim_buf_set_text heap-use-after-free (#19644) The line returned but ml_get_buf() may be freed by another call to ml_get_buf(), so it is necessary to make a copy. --- src/nvim/api/buffer.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 1b1a161226..d3895d31cf 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -565,27 +565,33 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In return; } - char *str_at_start = (char *)ml_get_buf(buf, (linenr_T)start_row, false); - if (start_col < 0 || (size_t)start_col > strlen(str_at_start)) { + char *str_at_start = NULL; + char *str_at_end = NULL; + + // Another call to ml_get_buf() may free the line, so make a copy. + str_at_start = xstrdup((char *)ml_get_buf(buf, (linenr_T)start_row, false)); + size_t len_at_start = strlen(str_at_start); + if (start_col < 0 || (size_t)start_col > len_at_start) { api_set_error(err, kErrorTypeValidation, "start_col out of bounds"); - return; + goto early_end; } - char *str_at_end = (char *)ml_get_buf(buf, (linenr_T)end_row, false); + // Another call to ml_get_buf() may free the line, so make a copy. + str_at_end = xstrdup((char *)ml_get_buf(buf, (linenr_T)end_row, false)); size_t len_at_end = strlen(str_at_end); if (end_col < 0 || (size_t)end_col > len_at_end) { api_set_error(err, kErrorTypeValidation, "end_col out of bounds"); - return; + goto early_end; } if (start_row > end_row || (end_row == start_row && start_col > end_col)) { api_set_error(err, kErrorTypeValidation, "start is higher than end"); - return; + goto early_end; } bool disallow_nl = (channel_id != VIML_INTERNAL_CALL); if (!check_string_array(replacement, disallow_nl, err)) { - return; + goto early_end; } size_t new_len = replacement.size; @@ -597,7 +603,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In if (start_row == end_row) { old_byte = (bcount_t)end_col - start_col; } else { - old_byte += (bcount_t)strlen(str_at_start) - start_col; + old_byte += (bcount_t)len_at_start - start_col; for (int64_t i = 1; i < end_row - start_row; i++) { int64_t lnum = start_row + i; @@ -611,7 +617,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In String last_item = replacement.items[replacement.size - 1].data.string; size_t firstlen = (size_t)start_col + first_item.size; - size_t last_part_len = strlen(str_at_end) - (size_t)end_col; + size_t last_part_len = len_at_end - (size_t)end_col; if (replacement.size == 1) { firstlen += last_part_len; } @@ -751,6 +757,10 @@ end: xfree(lines); aucmd_restbuf(&aco); try_end(err); + +early_end: + xfree(str_at_start); + xfree(str_at_end); } /// Gets a range from the buffer. -- cgit From ad7064bd83aef7caadb51c988c0dcb9054624fcf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 6 Aug 2022 17:14:37 +0800 Subject: vim-patch:8.1.1210: support for user commands is spread out (#19653) Problem: Support for user commands is spread out. No good reason to make user commands optional. Solution: Move user command support to usercmd.c. Always enable the user_commands feature. https://github.com/vim/vim/commit/ac9fb18020d7e8bf16d02d45fbb02cf47328aaf7 --- src/nvim/api/command.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index 04242932c9..bc766ff39c 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -14,6 +14,7 @@ #include "nvim/lua/executor.h" #include "nvim/ops.h" #include "nvim/regexp.h" +#include "nvim/usercmd.h" #include "nvim/window.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit