]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.2010: [security] use-after-free from buf_contents_changed() v9.0.2010
authorChristian Brabandt <cb@256bit.org>
Wed, 11 Oct 2023 19:08:13 +0000 (21:08 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 11 Oct 2023 19:09:53 +0000 (21:09 +0200)
Problem:  [security] use-after-free from buf_contents_changed()
Solution: block autocommands

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/buffer.c
src/testdir/crash/editing_arg_idx_POC_1 [new file with mode: 0644]
src/testdir/test_crash.vim
src/version.c

index 93f9245f27f9d042a07da81e65c0f0e4d18f0b72..9ee74f54dd6fd3648dff55cee48b78324a163541 100644 (file)
@@ -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 (file)
index 0000000..5d048d0
Binary files /dev/null and b/src/testdir/crash/editing_arg_idx_POC_1 differ
index 9a80340c285d4f482ac814110787cd20b546760b..5cd07e2a3f0b53a0ec5b766a6f86b1f29fab18e7 100644 (file)
@@ -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, '$'))
index 458b46a3713656bc36a23d1619c0952c4fa16e7b..0479f2096d42e7628671e23ca958c27c049d482e 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2010,
 /**/
     2009,
 /**/