* commands/read.c (grub_getline): Fix invalid memory access.
Don't add newline to the variable value.
2008-07-11 Pavel Roskin <proski@gnu.org>
+ * commands/read.c (grub_getline): Fix invalid memory access.
+ Don't add newline to the variable value.
+
* term/i386/pc/serial.c (GRUB_SERIAL_PORT_NUM): New constant.
[!GRUB_MACHINE_PCBIOS] (serial_hw_io_addr): Add COM2 and COM3.
(serial_hw_get_port): Check validity of the port number.
int i;
char *line;
char *tmp;
+ char c;
i = 0;
line = grub_malloc (1 + i + sizeof('\0'));
if (! line)
return NULL;
- while ((line[i - 1] != '\n') && (line[i - 1] != '\r'))
+ while (1)
{
- line[i] = grub_getkey ();
- if (grub_isprint (line[i]))
- grub_putchar (line[i]);
+ c = grub_getkey ();
+ if ((c == '\n') || (c == '\r'))
+ break;
+
+ line[i] = c;
+ if (grub_isprint (c))
+ grub_putchar (c);
i++;
tmp = grub_realloc (line, 1 + i + sizeof('\0'));
if (! tmp)