qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] char: cadence: check divider against baud rate
@ 2016-10-18  9:47 P J P
  2016-10-18  9:50 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
  0 siblings, 1 reply; 12+ messages in thread
From: P J P @ 2016-10-18  9:47 UTC (permalink / raw)
  To: Qemu Developers
  Cc: Edgar E . Iglesias, Huawei PSIRT, Alistair Francis, qemu-arm,
	Prasad J Pandit

From: Prasad J Pandit <pjp@fedoraproject.org>

The Cadence UART device emulator calculates speed by dividing the
baud rate by a divider. If this divider was to be zero or if baud
rate was to be lesser than the divider, it could lead to a divide
by zero error. Add check to avoid it.

Reported-by: Huawei PSIRT <psirt@huawei.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 hw/char/cadence_uart.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index e3bc52f..b18dd7f 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -170,6 +170,10 @@ static void uart_parameters_setup(CadenceUARTState *s)
     baud_rate = (s->r[R_MR] & UART_MR_CLKS) ?
             UART_INPUT_CLK / 8 : UART_INPUT_CLK;
 
+    if (!s->r[R_BRGR] || !(s->r[R_BDIV] + 1)
+        || baud_rate < (s->r[R_BRGR] * (s->r[R_BDIV] + 1))) {
+        return;
+    }
     ssp.speed = baud_rate / (s->r[R_BRGR] * (s->r[R_BDIV] + 1));
     packet_size = 1;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-10-25  0:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-18  9:47 [Qemu-devel] [PATCH] char: cadence: check divider against baud rate P J P
2016-10-18  9:50 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
2016-10-18 18:46   ` P J P
2016-10-19  9:49     ` Alistair Francis
2016-10-19 10:11       ` P J P
2016-10-19 13:42         ` Alistair Francis
2016-10-20  5:55           ` P J P
2016-10-20 17:21             ` Edgar E. Iglesias
2016-10-21  7:47               ` P J P
2016-10-24  7:46                 ` Alistair Francis
2016-10-24 13:25                   ` P J P
2016-10-25  0:28                     ` Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).