]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Avoid division by zero in serial.
authorVladimir Serbinenko <phcoder@gmail.com>
Tue, 20 Jan 2015 19:41:36 +0000 (20:41 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Wed, 21 Jan 2015 16:42:13 +0000 (17:42 +0100)
ChangeLog
grub-core/term/ns8250.c
grub-core/term/serial.c

index 7b34ba794352c67f586a212064c1d03db5f68306..7d5a651eddcc5e5bbcdf43dd52ee50badcc610b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 2959632a95aa82fc29b9cdacb18f83adfdc6959e..39809d0423b22ac5d3b97159d64a6ba0a0dcf368 100644 (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;
index 5784bc27ee67075b979c5b5cc29330aad3c0b1e9..db80b3ba0fb25ee96397259827d93054e8c7cd57 100644 (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)