patch 9.2.0586: Crash with TextPut autocmd when pasting in terminal buffer

Commit: 
https://github.com/vim/vim/commit/2e7833bde99295be6da67d75c16d2185712ffc3a
Author: Foxe Chen <[email protected]>
Date:   Mon Jun 1 21:08:20 2026 +0000

    patch 9.2.0586: Crash with TextPut autocmd when pasting in terminal buffer
    
    Problem:  Crash with TextPut autocmd when pasting in normal mode in a
              terminal buffer.
    Solution: Skip the TextPut autocmds when reg and insert are both NULL
              and regname is not '.' (Foxe Chen).
    
    closes: #20407
    
    Signed-off-by: Foxe Chen <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/register.c b/src/register.c
index 9daa7729e..358fe6454 100644
--- a/src/register.c
+++ b/src/register.c
@@ -1190,6 +1190,11 @@ put_do_autocmd(
     if (recursive || regname == '_')
        return;
 
+    if (regname != '.' && insert == NULL
+           && reg == NULL)
+       // Can happen when pasting text in normal mode in a terminal buffer
+       return;
+
     v_event = get_v_event(&save_v_event);
 
     list = list_alloc();
@@ -1219,7 +1224,6 @@ put_do_autocmd(
     }
     else
     {
-       assert(reg != NULL);
        for (n = 0; n < reg->y_size; n++)
            list_append_string(list, reg->y_array[n].string,
                    (int)reg->y_array[n].length);
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index a1f282e06..54116a585 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -6094,7 +6094,35 @@ func Test_TextPutX()
   unlet g:post_event
   unlet g:pre_event
   bwipe!
+endfunc
+
+" Test that attempting to put text in normal mode terminal buffer does not
+" result in a crash. This only happens when terminal is only window in tabpage
+" it seems.
+func Test_TextPutPost_term_norm()
+  CheckFeature terminal
+
+  tabnew
+  term ++curwin
+
+  let bnr = bufnr('$')
+  call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
+
+  call feedkeys("\<C-\>\<C-N>", 'xt')
+  call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
 
+  let err = 0
+
+  try
+    call feedkeys("p", 'xt')
+  catch /^Vim\%((\S\+)\)\=:E21:/
+    let err = 1
+  endtry
+
+  call assert_true(err)
+
+  unlet err
+  bwipe!
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index be7bb521b..e020aedc5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    586,
 /**/
     585,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1wU9yS-000dlH-82%40256bit.org.

Raspunde prin e-mail lui