From 947414b4b9935e1e8ddd3951ea31f9042adb76d9 Mon Sep 17 00:00:00 2001 From: proski Date: Fri, 11 Jul 2008 16:40:45 +0000 Subject: [PATCH] 2008-07-11 Pavel Roskin * 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. (grub_cmd_serial): Check return value of serial_hw_get_port(). --- ChangeLog | 7 +++++++ term/i386/pc/serial.c | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc6987212..c80282e2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-07-11 Pavel Roskin + + * 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. + (grub_cmd_serial): Check return value of serial_hw_get_port(). + 2008-07-07 Pavel Roskin * boot/i386/pc/diskboot.S (notification_string): Replace diff --git a/term/i386/pc/serial.c b/term/i386/pc/serial.c index 762d4e9c0..2d76ec1f8 100644 --- a/term/i386/pc/serial.c +++ b/term/i386/pc/serial.c @@ -67,15 +67,20 @@ static struct serial_port serial_settings; #ifdef GRUB_MACHINE_PCBIOS /* The BIOS data area. */ static const unsigned short *serial_hw_io_addr = (const unsigned short *) 0x0400; +#define GRUB_SERIAL_PORT_NUM 4 #else -static const unsigned short serial_hw_io_addr[] = { 0x3f8, 0x2f8 }; +static const unsigned short serial_hw_io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; +#define GRUB_SERIAL_PORT_NUM (sizeof(serial_hw_io_addr)/(serial_hw_io_addr[0])) #endif /* Return the port number for the UNITth serial device. */ static inline unsigned short -serial_hw_get_port (const unsigned short unit) +serial_hw_get_port (const unsigned int unit) { - return serial_hw_io_addr[unit]; + if (unit < GRUB_SERIAL_PORT_NUM) + return serial_hw_io_addr[unit]; + else + return 0; } /* Fetch a key. */ @@ -490,14 +495,14 @@ grub_cmd_serial (struct grub_arg_list *state, { struct serial_port backup_settings = serial_settings; grub_err_t hwiniterr; - int arg; if (state[0].set) { - arg = grub_strtoul (state[0].arg, 0, 0); - if (arg >= 0 && arg < 4) - serial_settings.port = serial_hw_get_port ((int) arg); - else + unsigned int unit; + + unit = grub_strtoul (state[0].arg, 0, 0); + serial_settings.port = serial_hw_get_port (unit); + if (!serial_settings.port) return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad unit number."); }