]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
commands/read: Fix overflow in grub_getline()
authorLi Gen <ligenlive@gmail.com>
Fri, 26 Aug 2022 00:59:09 +0000 (19:59 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 4 Oct 2022 13:38:39 +0000 (15:38 +0200)
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.

Signed-off-by: Li Gen <ligenlive@gmail.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/commands/read.c

index c2969ccda4bc08793152064541e9974f219df278..597c907065bf6433dc6dede22e19af19c752f210 100644 (file)
@@ -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'));