Avoid division by zero in serial.

This commit is contained in:
Vladimir Serbinenko 2015-01-20 20:41:36 +01:00
parent 4816dcac19
commit e95685dab1
3 changed files with 17 additions and 1 deletions

View file

@ -1,3 +1,10 @@
2015-01-20 Vladimir Serbinenko <phcoder@gmail.com>
Avoid division by zero in serial.
* grub-core/term/serial.c (grub_cmd_serial): Ensure speed is not 0.
* grub-core/term/ns8250.c (serial_get_divisor): Exit if speed is 0.
2015-01-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/video/readers/jpeg.c: Avoid sivision by zero.

View file

@ -57,6 +57,8 @@ serial_get_divisor (const struct grub_serial_port *port __attribute__ ((unused))
base_clock = config->base_clock ? (config->base_clock >> 4) : DEFAULT_BASE_CLOCK;
divisor = (base_clock + (config->speed / 2)) / config->speed;
if (config->speed == 0)
return 0;
if (divisor > 0xffff || divisor == 0)
return 0;
actual_speed = base_clock / divisor;

View file

@ -220,8 +220,12 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
config = port->config;
if (state[OPTION_SPEED].set)
if (state[OPTION_SPEED].set) {
config.speed = grub_strtoul (state[OPTION_SPEED].arg, 0, 0);
if (config.speed == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("unsupported serial port parity"));
}
if (state[OPTION_WORD].set)
config.word_len = grub_strtoul (state[OPTION_WORD].arg, 0, 0);
@ -275,6 +279,9 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
config.base_clock *= 1000;
}
if (config.speed == 0)
config.speed = 9600;
/* Initialize with new settings. */
err = port->driver->configure (port, &config);
if (err)