Skip to content

Commit 3bd7fa1

Browse files
committed
patch 9.0.1969: [security] buffer-overflow in trunc_string()
Problem: buffer-overflow in trunc_string() Solution: Add NULL at end of buffer Currently trunc_string() assumes that when the string is too long, buf[e-1] will always be writeable. But that assumption may not always be true. The condition currently looks like this else if (e + 3 < buflen) [...] else { // can't fit in the "...", just truncate it buf[e - 1] = NUL; } but this means, we may run into the last else clause with e still being larger than buflen. So a buffer overflow occurs. So instead of using `buf[e - 1]`, let's just always truncate at `buf[buflen - 1]` which should always be writable. Signed-off-by: Christian Brabandt <[email protected]>
1 parent 6ee7b52 commit 3bd7fa1

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/message.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ trunc_string(
353353
else
354354
{
355355
// can't fit in the "...", just truncate it
356-
buf[e - 1] = NUL;
356+
buf[buflen - 1] = NUL;
357357
}
358358
}
359359

src/testdir/test_crash.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ func Test_crash1()
6666
\ ' && echo "crash 7: [OK]" >> X_crash1_result.txt' .. "\<cr>")
6767
call TermWait(buf, 3000)
6868

69+
let file = 'crash/vim_msg_trunc_poc'
70+
let args = printf(cmn_args, vim, file)
71+
call term_sendkeys(buf, args ..
72+
\ ' || echo "crash 8: [OK]" >> X_crash1_result.txt' .. "\<cr>")
73+
call TermWait(buf, 3000)
74+
6975
" clean up
7076
exe buf .. "bw!"
7177

@@ -79,6 +85,7 @@ func Test_crash1()
7985
\ 'crash 5: [OK]',
8086
\ 'crash 6: [OK]',
8187
\ 'crash 7: [OK]',
88+
\ 'crash 8: [OK]',
8289
\ ]
8390

8491
call assert_equal(expected, getline(1, '$'))

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+
1969,
707709
/**/
708710
1968,
709711
/**/

0 commit comments

Comments
 (0)