termpty: better handle ';' in escape sequences. Closes T7475

This commit is contained in:
Boris Faure 2018-11-19 23:12:00 +01:00
parent 15ec4cb8d4
commit 3f432544df
1 changed files with 298 additions and 291 deletions

View File

@ -104,9 +104,11 @@ _csi_arg_get(Eina_Unicode **ptr)
*ptr = b;
return -1;
}
if (!*b)
goto error;
if (*b == '\0')
{
*ptr = NULL;
return -1;
}
while ((*b >= '0') && (*b <= '9'))
{
@ -119,15 +121,21 @@ _csi_arg_get(Eina_Unicode **ptr)
if (*b == ';')
{
if (b[1])
b++;
*ptr = b;
}
else if (*b == '\0')
{
*ptr = NULL;
}
else
*ptr = b;
return sum;
error:
*ptr = NULL;
return -1;
return -2;
}
static void
@ -645,10 +653,10 @@ _handle_esc_csi_truecolor_cmyk(Termpty *ty, Eina_Unicode **ptr)
}
static void
_handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
_handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
const Eina_Unicode * const end)
{
Eina_Unicode *b = *ptr;
int first = 1;
if (b && (*b == '>'))
{ // key resources used by xterm
@ -656,16 +664,14 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
return;
}
DBG("color set");
while (b)
while (b && b <= end)
{
int arg = _csi_arg_get(&b);
if ((first) && (!b))
termpty_reset_att(&(ty->termstate.att));
else if (b)
{
first = 0;
DBG("arg=%d b:%p", arg, b);
switch (arg)
{
case -1:
EINA_FALLTHROUGH;
case 0: // reset to normal
termpty_reset_att(&(ty->termstate.att));
break;
@ -948,7 +954,6 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
}
}
}
}
static void
_handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
@ -1255,8 +1260,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
ERR("csi parsing overflowed, skipping the whole buffer (binary data?)");
return cc - c;
}
if (cc == ce) return 0;
*b = 0;
if (cc == ce)
return 0;
*b = '\0';
be = b;
b = buf;
DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf);
@ -1284,7 +1290,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
case 'A': // cursor up N (CUU)
CUU:
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
if (arg < 1)
arg = 1;
DBG("cursor up %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
@ -1625,7 +1632,7 @@ HVP:
_handle_esc_csi_reset_mode(ty, *cc, b);
break;
case 'm': // color set
_handle_esc_csi_color_set(ty, &b);
_handle_esc_csi_color_set(ty, &b, be);
break;
case 'n':
_handle_esc_csi_dsr(ty, b);