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

@@ -1489,7 +1489,7 @@ bool is_cmd_ni(cmdidx_T cmdidx)
/// @param[out] errormsg Error message, if any
///
/// @return Success or failure
bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, const char **errormsg)
bool parse_cmdline(char **cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, const char **errormsg)
{
char *after_modifier = NULL;
bool retval = false;
@@ -1507,8 +1507,8 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, const cha
*eap = (exarg_T){
.line1 = 1,
.line2 = 1,
.cmd = cmdline,
.cmdlinep = &cmdline,
.cmd = *cmdline,
.cmdlinep = cmdline,
.ea_getline = NULL,
.cookie = NULL,
};
@@ -1549,7 +1549,7 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, const cha
if (eap->cmdidx == CMD_SIZE) {
xstrlcpy(IObuff, _(e_not_an_editor_command), IOSIZE);
// If the modifier was parsed OK the error must be in the following command
char *cmdname = after_modifier ? after_modifier : cmdline;
char *cmdname = after_modifier ? after_modifier : *cmdline;
append_command(cmdname);
*errormsg = IObuff;
goto end;