Skip to contentSkip to conversation

read: Fix overflow in grub_getline()

PATCH In review Glenn Washburn 2 participants 2 messages Aug 26, 2022 – Sep 29, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 read: Fix overflow in grub_getline()

From: Li Gen <[email protected]>

Store returned value from grub_getkey() in int instead of char to prevent throwing away the extended bits. This was a problem because, for instance, the left arrow key press would return (GRUB_TERM_EXTENDED | 0x4b), which would have the GRUB_TERM_EXTENDED thrown away leaving 0x4b or 'K'. These extended keys should either work as intended or do nothing. This change has them do nothing, instead of inserting a key not pressed by the user.

---
 grub-core/commands/read.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
grub-core/commands/read.c +6 -3
index c2969ccda4..597c907065 100644
@@ -40,7 +40,7 @@ grub_getline (int silent)
   int i;
   char *line;
   char *tmp;
-  char c;
+  int c;
 
   i = 0;
   line = grub_malloc (1 + i + sizeof('\0'));
@@ -53,8 +53,11 @@ grub_getline (int silent)
       if ((c == '\n') || (c == '\r'))
 	break;
 
-      line[i] = c;
-      if (!silent && grub_isprint (c))
+      if (!grub_isprint (c))
+	continue;
+
+      line[i] = (char) c;
+      if (!silent)
 	grub_printf ("%c", c);
       i++;
       tmp = grub_realloc (line, 1 + i + sizeof('\0'));
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Glenn Washburn

From: Li Gen <[email protected]>

Store returned value from grub_getkey() in int instead of char to prevent throwing away the extended bits. This was a problem because, for instance, the left arrow key press would return (GRUB_TERM_EXTENDED | 0x4b), which would have the GRUB_TERM_EXTENDED thrown away leaving 0x4b or 'K'. These extended keys should either work as intended or do nothing. This change has them do nothing, instead of inserting a key not pressed by the user.

Quoted 2 lines

Daniel