Skip to content

Commit 77e7a40

Browse files
mattnchrisbra
authored andcommitted
patch 9.2.0297: libvterm: can improve CSI overflow code
Problem: libvterm: can improve CSI overflow code Solution: Handle overflow cases better (Yasuhiro Matsumoto) closes: #19903 Signed-off-by: Yasuhiro Matsumoto <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 18cd55d commit 77e7a40

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/libvterm/src/parser.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,16 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
230230
case CSI_ARGS:
231231
/* Numerical value of argument */
232232
if(c >= '0' && c <= '9') {
233-
if(vt->parser.v.csi.args[vt->parser.v.csi.argi] == CSI_ARG_MISSING)
234-
vt->parser.v.csi.args[vt->parser.v.csi.argi] = 0;
235-
if(vt->parser.v.csi.args[vt->parser.v.csi.argi] < (CSI_ARG_MISSING - 9) / 10) {
236-
vt->parser.v.csi.args[vt->parser.v.csi.argi] *= 10;
237-
vt->parser.v.csi.args[vt->parser.v.csi.argi] += c - '0';
238-
}
233+
long arg_max = CSI_ARG_MISSING - 1;
234+
long *arg = &vt->parser.v.csi.args[vt->parser.v.csi.argi];
235+
int digit = c - '0';
236+
237+
if(*arg == CSI_ARG_MISSING)
238+
*arg = 0;
239+
if(*arg > (arg_max - digit) / 10)
240+
*arg = arg_max;
241+
else
242+
*arg = *arg * 10 + digit;
239243
break;
240244
}
241245
if(c == ':') {

src/testdir/test_terminal3.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,9 @@ endfunc
12321232
" Test that CSI sequences with more than CSI_ARGS_MAX arguments do not crash
12331233
func Test_terminal_csi_args_overflow()
12341234
CheckExecutable printf
1235-
let buf = term_start([&shell, &shellcmdflag,
1236-
\ 'printf "\033[' . repeat('1;', 49) . '1m"'])
1235+
let seq = "\033[" .. repeat('1;', 49) .. '1m'
1236+
let seq ..= "\033[1111111111111111111m"
1237+
let buf = term_start([&shell, &shellcmdflag, 'printf "' .. seq .. '"'])
12371238

12381239
" If we get here without a crash, the fix works
12391240
call assert_equal('running', term_getstatus(buf))

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+
297,
737739
/**/
738740
296,
739741
/**/

0 commit comments

Comments
 (0)