Skip to content

Commit

Permalink
hw/arm/omap1: Avoid unintended sign extension writing omap_rtc YEARS_REG
Browse files Browse the repository at this point in the history
When writing to the YEARS_REG register, if the year value is
99 then the multiplication by 31536000 will overflow into
the sign bit of a 32 bit value and then be erroneously
sign-extended if time_t is 64 bits. Add a cast to avoid this.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
  • Loading branch information
pm215 committed May 13, 2014
1 parent c94239f commit 7e7e585
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hw/arm/omap1.c
Expand Up @@ -2709,8 +2709,8 @@ static void omap_rtc_write(void *opaque, hwaddr addr,
s->ti += ti[1];
} else {
/* A less accurate version */
s->ti -= (s->current_tm.tm_year % 100) * 31536000;
s->ti += from_bcd(value) * 31536000;
s->ti -= (time_t)(s->current_tm.tm_year % 100) * 31536000;
s->ti += (time_t)from_bcd(value) * 31536000;
}
return;

Expand Down

0 comments on commit 7e7e585

Please sign in to comment.