grub2/0159-Avoid-division-by-zero-in-serial.patch
Peter Jones 8c6b1ac71e Reconcile with upstream once again.
Also include some minor fixes for gcc 5.1.1

Signed-off-by: Peter Jones <pjones@redhat.com>
2015-07-22 09:46:32 -04:00

73 lines
2.3 KiB
Diff

From e95685dab1a7b7ae31b65be1ebc3fd84ebc41c34 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phcoder@gmail.com>
Date: Tue, 20 Jan 2015 20:41:36 +0100
Subject: [PATCH 159/506] Avoid division by zero in serial.
---
ChangeLog | 7 +++++++
grub-core/term/ns8250.c | 2 ++
grub-core/term/serial.c | 9 ++++++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 7b34ba7..7d5a651 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
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.
2015-01-20 Vladimir Serbinenko <phcoder@gmail.com>
diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c
index 2959632..39809d0 100644
--- a/grub-core/term/ns8250.c
+++ b/grub-core/term/ns8250.c
@@ -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;
diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c
index 5784bc2..db80b3b 100644
--- a/grub-core/term/serial.c
+++ b/grub-core/term/serial.c
@@ -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)
--
2.4.3