patch 9.0.2010: [security] use-after-free from buf_contents_changed()

Commit: 
https://github.com/vim/vim/commit/41e6f7d6ba67b61d911f9b1d76325cd79224753d
Author: Christian Brabandt <[email protected]>
Date:   Wed Oct 11 21:08:13 2023 +0200

    patch 9.0.2010: [security] use-after-free from buf_contents_changed()
    
    Problem:  [security] use-after-free from buf_contents_changed()
    Solution: block autocommands
    
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/buffer.c b/src/buffer.c
index 93f9245f2..9ee74f54d 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -6013,6 +6013,9 @@ buf_contents_changed(buf_T *buf)
        return TRUE;
     }
 
+    // We don't want to trigger autocommands now, they may have nasty
+    // side-effects like wiping buffers
+    block_autocmds();
     if (ml_open(curbuf) == OK
            && readfile(buf->b_ffname, buf->b_fname,
                                  (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
@@ -6038,6 +6041,8 @@ buf_contents_changed(buf_T *buf)
     if (curbuf != newbuf)      // safety check
        wipe_buffer(newbuf, FALSE);
 
+    unblock_autocmds();
+
     return differ;
 }
 
diff --git a/src/testdir/crash/editing_arg_idx_POC_1 
b/src/testdir/crash/editing_arg_idx_POC_1
new file mode 100644
index 
0000000000000000000000000000000000000000..5d048d03405a31e268f30950dc11d9dc767103de
GIT binary patch
literal 398
zcmZwD!Ait15C-6Q&0W2Yy>wf2DbmwYi}(amL<%CBO(xw!n=DDn_NF)A!FTfFOZWty
z*Th|sivKAC^TU_ny6>4fIaACu7b(;@t_>8u7Pjng+-^-{OUeeP;cAc-GI4DXQos=-
zt0I`seSs-4iwd?JWEmwu<s;Ogk%sVIJn$7$4R)<vF_TcvI<hgXL)msXyNhdw*2#Tt
ze;zWS04Q27GKPM$;@US}&lmYZzd=RFGqr7(DU0x;O`nk`Ki^~u$HM=`mWO}T2fu1U
zlnB!1b0_5=lf3(B2ZaeV4^WQ|ggm}Kje{-z59-)b1yhyL&H9q6oKMbtJUO#pJlb!6
E0fTvuc>n+a

literal 0
HcmV?d00001

diff --git a/src/testdir/test_crash.vim b/src/testdir/test_crash.vim
index 9a80340c2..5cd07e2a3 100644
--- a/src/testdir/test_crash.vim
+++ b/src/testdir/test_crash.vim
@@ -78,6 +78,14 @@ func Test_crash1()
     \ '  && echo "crash 9: [OK]" >> X_crash1_result.txt' .. "\<cr>")
   call TermWait(buf, 1000)
 
+  let file = 'crash/editing_arg_idx_POC_1'
+  let args = printf(cmn_args, vim, file)
+  call term_sendkeys(buf, args ..
+    \ '  || echo "crash 10: [OK]" >> X_crash1_result.txt' .. "\<cr>")
+  call TermWait(buf, 1000)
+  call delete('Xerr')
+  call delete('@')
+
   " clean up
   exe buf .. "bw!"
 
@@ -93,6 +101,7 @@ func Test_crash1()
       \ 'crash 7: [OK]',
       \ 'crash 8: [OK]',
       \ 'crash 9: [OK]',
+      \ 'crash 10: [OK]',
       \ ]
 
   call assert_equal(expected, getline(1, '$'))
diff --git a/src/version.c b/src/version.c
index 458b46a37..0479f2096 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2010,
 /**/
     2009,
 /**/

-- 
-- 
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 on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1qqefk-0017oK-VS%40256bit.org.

Raspunde prin e-mail lui