case CSI_ARGS:
/* Numerical value of argument */
if(c >= '0' && c <= '9') {
- if(vt->parser.v.csi.args[vt->parser.v.csi.argi] == CSI_ARG_MISSING)
- vt->parser.v.csi.args[vt->parser.v.csi.argi] = 0;
- if(vt->parser.v.csi.args[vt->parser.v.csi.argi] < (CSI_ARG_MISSING - 9) / 10) {
- vt->parser.v.csi.args[vt->parser.v.csi.argi] *= 10;
- vt->parser.v.csi.args[vt->parser.v.csi.argi] += c - '0';
- }
+ long arg_max = CSI_ARG_MISSING - 1;
+ long *arg = &vt->parser.v.csi.args[vt->parser.v.csi.argi];
+ int digit = c - '0';
+
+ if(*arg == CSI_ARG_MISSING)
+ *arg = 0;
+ if(*arg > (arg_max - digit) / 10)
+ *arg = arg_max;
+ else
+ *arg = *arg * 10 + digit;
break;
}
if(c == ':') {
" Test that CSI sequences with more than CSI_ARGS_MAX arguments do not crash
func Test_terminal_csi_args_overflow()
CheckExecutable printf
- let buf = term_start([&shell, &shellcmdflag,
- \ 'printf "\033[' . repeat('1;', 49) . '1m"'])
+ let seq = "\033[" .. repeat('1;', 49) .. '1m'
+ let seq ..= "\033[1111111111111111111m"
+ let buf = term_start([&shell, &shellcmdflag, 'printf "' .. seq .. '"'])
" If we get here without a crash, the fix works
call assert_equal('running', term_getstatus(buf))
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 297,
/**/
296,
/**/