Skip to content

Commit

Permalink
patch 9.0.2010: [security] use-after-free from buf_contents_changed()
Browse files Browse the repository at this point in the history
Problem:  [security] use-after-free from buf_contents_changed()
Solution: block autocommands

Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
chrisbra committed Oct 11, 2023
1 parent 5484485 commit 41e6f7d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/buffer.c
Expand Up @@ -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,
Expand All @@ -6038,6 +6041,8 @@ buf_contents_changed(buf_T *buf)
if (curbuf != newbuf) // safety check
wipe_buffer(newbuf, FALSE);

unblock_autocmds();

return differ;
}

Expand Down
Binary file added src/testdir/crash/editing_arg_idx_POC_1
Binary file not shown.
9 changes: 9 additions & 0 deletions src/testdir/test_crash.vim
Expand Up @@ -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!"

Expand All @@ -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, '$'))
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2010,
/**/
2009,
/**/
Expand Down

0 comments on commit 41e6f7d

Please sign in to comment.