]> granicus.if.org Git - vim/commitdiff
patch 8.1.2420: crash when calling popup_close() in win_execute() v8.1.2420
authorBram Moolenaar <Bram@vim.org>
Wed, 11 Dec 2019 18:34:54 +0000 (19:34 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 11 Dec 2019 18:34:54 +0000 (19:34 +0100)
Problem:    Crash when calling popup_close() in win_execute().
Solution:   Disallow popup_close() in popup window. (Yasuhiro Matsumoto,
            closes #5345)

src/popupwin.c
src/testdir/test_popupwin.vim
src/version.c

index dc09ef3a57d263c758eb7c0e3cd93d610a8f5cc5..e65b4bf4404044d5c5f39fdde6c31733e07c1d13 100644 (file)
@@ -1753,7 +1753,7 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
        // 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, typval_T *arg)
 {
     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]);
 }
index 5d7f46f9a37acbe9caf9a604caaa5bc0a0747db2..d5ee7160a13363b3dd225047cc203cb336c343d0 100644 (file)
@@ -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! :\<C-u>call popup_close(%d)\<CR>", winid))', 'E994')
+  call popup_clear()
 endfunc
 
 func Test_win_execute_not_allowed()
index 2b992df9490a28783423ad4e277a2667561160de..7b36fe320f9b9386a9072778d9b3ebcefb86e437 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2420,
 /**/
     2419,
 /**/