[PATCH 02/20] fbconsole: improve handling of unexpected escape sequences
Ahmad Fatoum
a.fatoum at barebox.org
Sun May 3 01:33:04 PDT 2026
enum state_t describes the state the parser is in: literal input,
escape or CSI.
The way we currently parse it has expectations on the input that does
not match standard terminal behavior and may lead the state machine
getting stuck in a mode when getting control characters in an unexpected
order.
Improve this by supporting following corner cases:
- In ESC mode, if a non-'[' character is received, reset to LIT.
- In CSI mode, if ESC is received, transition to ESC.
- In CSI mode, always reset the DEC private mode when transitioning out.
So far this happened only in the successful cases.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
drivers/video/fbconsole.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 60e9783266b6..2461ab2fb849 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -558,7 +558,6 @@ static void fbc_parse_csi(struct fbc_priv *priv)
/* suffix for vt100 "[?25h" */
switch (priv->csi_cmd) {
case '?': /* cursor visible */
- priv->csi_cmd = -1;
if (!(priv->flags & HIDE_CURSOR))
break;
@@ -572,8 +571,6 @@ static void fbc_parse_csi(struct fbc_priv *priv)
/* suffix for vt100 "[?25l" */
switch (priv->csi_cmd) {
case '?': /* cursor invisible */
- priv->csi_cmd = -1;
-
/* hide cursor now */
video_invertchar(priv, priv->x, priv->y);
priv->flags |= HIDE_CURSOR;
@@ -658,13 +655,23 @@ static void fbc_putc(struct console_device *cdev, char c)
priv->csipos = 0;
memset(priv->csi, 0, 6);
break;
+ default:
+ priv->state = LIT;
+ break;
}
break;
case CSI:
+ if (c == '\033') {
+ priv->state = ESC;
+ priv->csi_cmd = -1;
+ break;
+ }
+
priv->csi[priv->csipos++] = c;
if (priv->csipos == 255) {
priv->csipos = 0;
priv->state = LIT;
+ priv->csi_cmd = -1;
return;
}
@@ -683,6 +690,7 @@ static void fbc_putc(struct console_device *cdev, char c)
default:
fbc_parse_csi(priv);
priv->state = LIT;
+ priv->csi_cmd = -1;
}
break;
}
--
2.47.3
More information about the barebox
mailing list