vim-patch:8.2.4975: recursive command line loop may cause a crash (#18614)

Problem:    Recursive command line loop may cause a crash.
Solution:   Limit recursion of getcmdline().
51f0bfb88a

Cherry-pick e_command_too_recursive from patch 8.2.3957.
This commit is contained in:
zeertzjq
2022-05-18 08:21:24 +08:00
committed by GitHub
parent 38cbca3eea
commit 7ded303d68
4 changed files with 24 additions and 4 deletions

View File

@@ -804,6 +804,12 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init
ccline.cmdlen = s->indent;
}
if (cmdline_level == 50) {
// Somehow got into a loop recursively calling getcmdline(), bail out.
emsg(_(e_command_too_recursive));
goto theend;
}
ExpandInit(&s->xpc);
ccline.xpc = &s->xpc;
@@ -995,12 +1001,13 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init
State = s->save_State;
setmouse();
ui_cursor_shape(); // may show different cursor shape
sb_text_end_cmdline();
theend:
xfree(s->save_p_icm);
xfree(ccline.last_colors.cmdbuff);
kv_destroy(ccline.last_colors.colors);
sb_text_end_cmdline();
char_u *p = ccline.cmdbuff;
if (ui_has(kUICmdline)) {