]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1859: heap-use-after-free in bt_normal() v9.0.1859
authorChristian Brabandt <cb@256bit.org>
Sun, 3 Sep 2023 19:43:46 +0000 (21:43 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 3 Sep 2023 19:43:46 +0000 (21:43 +0200)
Problem:  heap-use-after-free in bt_normal()
Solution: check that buffer is still valid

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

index 14eac92b972a89792e5a53ba06184b2472e02fc1..93f9245f27f9d042a07da81e65c0f0e4d18f0b72 100644 (file)
@@ -5777,7 +5777,7 @@ bt_normal(buf_T *buf)
 bt_quickfix(buf_T *buf UNUSED)
 {
 #ifdef FEAT_QUICKFIX
-    return buf != NULL && buf->b_p_bt[0] == 'q';
+    return buf != NULL && buf_valid(buf) && buf->b_p_bt[0] == 'q';
 #else
     return FALSE;
 #endif
diff --git a/src/testdir/crash/bt_quickfix1_poc b/src/testdir/crash/bt_quickfix1_poc
new file mode 100644 (file)
index 0000000..97993fd
--- /dev/null
@@ -0,0 +1,5 @@
+au BufReadPre * exe 'sn' .. expand("<abuf>")
+call writefile([''],'X')
+sil! e X
+call writefile([''],'X')
+sil! e X
index 27bf7b55d46e1b377f36a387753de04777477021..8deb79702b88b7c84d1ca0aef9de8083d2453037 100644 (file)
@@ -49,6 +49,15 @@ func Test_crash1()
 
   call TermWait(buf, 100)
 
+  let file = 'crash/bt_quickfix1_poc'
+  let args = printf(cmn_args, vim, file)
+  call term_sendkeys(buf, args ..
+    \ '  && echo "crash 6: [OK]" >> X_crash1_result.txt' .. "\<cr>")
+  " clean up
+  call delete('X')
+  " This test takes a bit longer
+  call TermWait(buf, 200)
+
   " clean up
   exe buf .. "bw!"
 
@@ -60,6 +69,7 @@ func Test_crash1()
       \ 'crash 3: [OK]',
       \ 'crash 4: [OK]',
       \ 'crash 5: [OK]',
+      \ 'crash 6: [OK]',
       \ ]
 
   call assert_equal(expected, getline(1, '$'))
index b604b57f8b37c2a48a3a03e1168928b26f6a36a1..f2ff8d6b7031ee1294794bdf285f694ea4cac454 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1859,
 /**/
     1858,
 /**/