summaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2016-01-06 22:17:32 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2016-01-07 08:46:10 +0100
commit645320b94aaa0f478d31809673df6f83964c5292 (patch)
treef9b98fa7db0b028d52ee947bf1800735859a8591 /drivers/rtc
parent304cdde1677a77af010241801454dd58f2675fbe (diff)
downloadbarebox-645320b94aaa0f478d31809673df6f83964c5292.tar.gz
barebox-645320b94aaa0f478d31809673df6f83964c5292.tar.xz
rtc-lib: Check tm_wday for validity in rtc_valid_tm()
RTC drivers rely on rtc_valid_tm() in order to make sure that no bogus values from uninitialized HW registers get passed to the uppper layers. A somewhat contrived way to reproduce this problem with DS1307 RTC would be to do the following: > i2c_write -b <bus> -a <addr> -r 3 0x00 > hwclock Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-lib.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 1b23458a57..83d80455da 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -90,6 +90,8 @@ int rtc_valid_tm(struct rtc_time *tm)
{
if (tm->tm_year < 70
|| ((unsigned)tm->tm_mon) >= 12
+ || tm->tm_wday < 0
+ || tm->tm_wday > 6
|| tm->tm_mday < 1
|| tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900)
|| ((unsigned)tm->tm_hour) >= 24