fix(api): fix crash in command preview with % #35228

Problem: parse_cmdline() sets eap->cmdlinep to address of local parameter,
causing invalid memory access when expand_filename() tries to modify it.
This leads to crashes when typing '%' in user commands with preview=true
and complete=file.

Solution: Change parse_cmdline() signature to accept char **cmdline,
allowing cmdlinep to point to caller's variable for safe reallocation.
This commit is contained in:
glepnir
2025-08-13 04:43:56 +08:00
committed by GitHub
parent 3eab5bd38a
commit c7c3f9fc9c
4 changed files with 25 additions and 6 deletions

View File

@@ -134,7 +134,7 @@ Dict(cmd) nvim_parse_cmd(String str, Dict(empty) *opts, Arena *arena, Error *err
char *cmdline = arena_memdupz(arena, str.data, str.size);
const char *errormsg = NULL;
if (!parse_cmdline(cmdline, &ea, &cmdinfo, &errormsg)) {
if (!parse_cmdline(&cmdline, &ea, &cmdinfo, &errormsg)) {
if (errormsg != NULL) {
api_set_error(err, kErrorTypeException, "Parsing command-line: %s", errormsg);
} else {