# HG changeset patch # User Bram Moolenaar # Date 1576089904 -3600 # Node ID 5fbb167591fcf0158d77777dd5e323260f6d5027 # Parent c9409f359583dedd09b70c7fe79a90b20ea4ba07 patch 8.1.2420: crash when calling popup_close() in win_execute() Commit: https://github.com/vim/vim/commit/4954019c93a2bb5a0b1af54b5961c933beeb56f4 Author: Bram Moolenaar Date: Wed Dec 11 19:34:54 2019 +0100 patch 8.1.2420: crash when calling popup_close() in win_execute() Problem: Crash when calling popup_close() in win_execute(). Solution: Disallow popup_close() in popup window. (Yasuhiro Matsumoto, closes #5345) diff --git a/src/popupwin.c b/src/popupwin.c --- a/src/popupwin.c +++ b/src/popupwin.c @@ -1753,7 +1753,7 @@ popup_create(typval_T *argvars, typval_T // Check that arguments look OK. if (argvars[0].v_type == VAR_NUMBER) { - buf = buflist_findnr( argvars[0].vval.v_number); + buf = buflist_findnr(argvars[0].vval.v_number); if (buf == NULL) { semsg(_(e_nobufnr), argvars[0].vval.v_number); @@ -2097,6 +2097,10 @@ popup_close_and_callback(win_T *wp, typv { int id = wp->w_id; + // Just in case a check higher up is missing. + if (wp == curwin && ERROR_IF_POPUP_WINDOW) + return; + if (wp->w_close_cb.cb_name != NULL) // Careful: This may make "wp" invalid. invoke_popup_callback(wp, arg); @@ -2331,8 +2335,12 @@ find_popup_win(int id) f_popup_close(typval_T *argvars, typval_T *rettv UNUSED) { int id = (int)tv_get_number(argvars); - win_T *wp = find_popup_win(id); - + win_T *wp; + + if (ERROR_IF_POPUP_WINDOW) + return; + + wp = find_popup_win(id); if (wp != NULL) popup_close_and_callback(wp, &argvars[1]); } diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -891,6 +891,10 @@ func Test_win_execute_closing_curwin() let winid = popup_create('some text', {}) call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994') call popup_clear() + + let winid = popup_create('some text', {}) + call assert_fails('call win_execute(winid, printf("normal! :\call popup_close(%d)\", winid))', 'E994') + call popup_clear() endfunc func Test_win_execute_not_allowed() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2420, +/**/ 2419, /**/ 2418,