Received: from eggs.gnu.org ([2001:4830:134:3::10]:39182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwVDR-0006Qb-La for qemu-devel@nongnu.org; Tue, 18 Oct 2016 10:18:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwVDQ-0006wg-R6 for qemu-devel@nongnu.org; Tue, 18 Oct 2016 10:18:05 -0400 From: P J P Date: Tue, 18 Oct 2016 19:47:49 +0530 Message-Id: <1476800269-31902-1-git-send-email-ppandit@redhat.com> Subject: [Qemu-devel] [PATCH] timer: stm32f2xx_timer: add check for prescaler value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qemu Developers Cc: Huawei PSIRT , Peter Maydell , qemu-arm@nongnu.org, Prasad J Pandit From: Prasad J Pandit The STM32F2XX Timer emulator uses a 16 bit prescaler value to limit the timer clock rate. It does that by dividing the timer frequency. If the prescaler 's->tim_psc' was set to be UINT_MAX, it'd lead to divide by zero error. Limit prescaler value to 16 bits to avoid it. Reported-by: Huawei PSIRT Signed-off-by: Prasad J Pandit --- hw/timer/stm32f2xx_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c index bf0fb28..2cad36d 100644 --- a/hw/timer/stm32f2xx_timer.c +++ b/hw/timer/stm32f2xx_timer.c @@ -208,7 +208,7 @@ static void stm32f2xx_timer_write(void *opaque, hwaddr offset, return; case TIM_PSC: timer_val = stm32f2xx_ns_to_ticks(s, now) - s->tick_offset; - s->tim_psc = value; + s->tim_psc = value & 0xFFFF; value = timer_val; break; case TIM_CNT: -- 2.7.4