Skip to content

Commit fe05143

Browse files
committed
patch 9.2.0279: terminal: out-of-bounds write with overlong CSI argument list
Problem: libvterm CSI parser does not bounds-check argi against CSI_ARGS_MAX, allowing excess ';'-separated arguments to write past the end of the args array (sentinel404). Solution: Drop excess arguments. Supported by AI Signed-off-by: Christian Brabandt <[email protected]>
1 parent b2e55ed commit fe05143

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/libvterm/src/parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
241241
c = ';';
242242
}
243243
if(c == ';') {
244+
if(vt->parser.v.csi.argi >= CSI_ARGS_MAX - 1)
245+
break; /* drop excess args */
244246
vt->parser.v.csi.argi++;
245247
vt->parser.v.csi.args[vt->parser.v.csi.argi] = CSI_ARG_MISSING;
246248
break;

src/testdir/test_terminal3.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,4 +1229,15 @@ func Test_term_autowrite()
12291229
set noautowrite
12301230
endfunc
12311231

1232+
" Test that CSI sequences with more than CSI_ARGS_MAX arguments do not crash
1233+
func Test_terminal_csi_args_overflow()
1234+
CheckExecutable printf
1235+
let buf = term_start([&shell, &shellcmdflag,
1236+
\ 'printf "\033[' . repeat('1;', 49) . '1m"'])
1237+
1238+
" If we get here without a crash, the fix works
1239+
call assert_equal('running', term_getstatus(buf))
1240+
call StopVimInTerminal(buf)
1241+
endfunc
1242+
12321243
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
279,
737739
/**/
738740
278,
739741
/**/

0 commit comments

Comments
 (0)