Skip to content

Commit 322ba91

Browse files
committed
patch 9.1.0697: [security]: heap-buffer-overflow in ins_typebuf
Problem: heap-buffer-overflow in ins_typebuf (SuyueGuo) Solution: When flushing the typeahead buffer, validate that there is enough space left Github Advisory: GHSA-4ghr-c62x-cqfh Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 663950d commit 322ba91

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/getchar.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,18 @@ flush_buffers(flush_buffers_T flush_typeahead)
446446

447447
if (flush_typeahead == FLUSH_MINIMAL)
448448
{
449-
// remove mapped characters at the start only
450-
typebuf.tb_off += typebuf.tb_maplen;
451-
typebuf.tb_len -= typebuf.tb_maplen;
449+
// remove mapped characters at the start only,
450+
// but only when enough space left in typebuf
451+
if (typebuf.tb_off + typebuf.tb_maplen >= typebuf.tb_buflen)
452+
{
453+
typebuf.tb_off = MAXMAPLEN;
454+
typebuf.tb_len = 0;
455+
}
456+
else
457+
{
458+
typebuf.tb_off += typebuf.tb_maplen;
459+
typebuf.tb_len -= typebuf.tb_maplen;
460+
}
452461
#if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL)
453462
if (typebuf.tb_len == 0)
454463
typebuf_was_filled = FALSE;

src/testdir/crash/heap_overflow3

700 Bytes
Binary file not shown.

src/testdir/test_crash.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ func Test_crash1_3()
216216
call term_sendkeys(buf, args)
217217
call TermWait(buf, 50)
218218

219+
let file = 'crash/heap_overflow3'
220+
let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
221+
let args = printf(cmn_args, vim, file)
222+
call term_sendkeys(buf, args)
223+
call TermWait(buf, 150)
224+
225+
219226
" clean up
220227
exe buf .. "bw!"
221228
bw!

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
697,
707709
/**/
708710
696,
709711
/**/

0 commit comments

Comments
 (0)