[PATCH 09/25] efi-stdio: fix escape sequence end detection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



So far we only correctly parse the escape sequence we know. Detect the
possible end characters of the escape sequence upfront so that we
at least consume the correct number of character, eventhough the escape
sequence might be unknown and ignored.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 drivers/serial/efi-stdio.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index 0c804a5d97..c00c05b843 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -179,10 +179,17 @@ static int efi_process_square_bracket(struct efi_console_priv *priv, const char
 {
 	int x, y;
 	char *endp;
+	int retlen;
+
+	endp = strpbrk(inp, "ABCDEFGHJKmr");
+	if (!endp)
+		return 0;
+
+	retlen = endp - inp + 1;
 
 	inp++;
 
-	switch (*inp) {
+	switch (*endp) {
 	case 'A':
 		/* Cursor up */
 	case 'B':
@@ -195,27 +202,27 @@ static int efi_process_square_bracket(struct efi_console_priv *priv, const char
 		/* home */
 	case 'F':
 		/* end */
-		return 2;
+		return retlen;
 	case 'K':
 		clear_to_eol(priv);
-		return 2;
+		return retlen;
 	}
 
 	if (*inp == '2' && *(inp + 1) == 'J') {
 		priv->out->clear_screen(priv->out);
-		return 3;
+		return retlen;
 	}
 
 	if (*inp == '0' && *(inp + 1) == 'm') {
 		priv->out->set_attribute(priv->out,
 				EFI_TEXT_ATTR(EFI_WHITE, EFI_BLACK));
-		return 3;
+		return retlen;
 	}
 
 	if (*inp == '7' && *(inp + 1) == 'm') {
 		priv->out->set_attribute(priv->out,
 				EFI_TEXT_ATTR(EFI_BLACK, priv->current_color));
-		return 3;
+		return retlen;
 	}
 
 	if (*inp == '1' &&
@@ -239,7 +246,7 @@ static int efi_process_square_bracket(struct efi_console_priv *priv, const char
 
 		priv->out->set_attribute(priv->out,
 				EFI_TEXT_ATTR(color, EFI_BLACK));
-		return 6;
+		return retlen;
 	}
 
 	y = simple_strtoul(inp, &endp, 10);
@@ -247,11 +254,11 @@ static int efi_process_square_bracket(struct efi_console_priv *priv, const char
 		x = simple_strtoul(endp + 1, &endp, 10);
 		if (*endp == 'H') {
 			priv->out->set_cursor_position(priv->out, x - 1, y - 1);
-			return endp - inp + 2;
+			return retlen;
 		}
 	}
 
-	return 7;
+	return retlen;
 }
 
 static int efi_process_escape(struct efi_console_priv *priv, const char *inp)
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux