mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 3/6] rtc-lib: Check tm_wday for validity in rtc_valid_tm()
Date: Wed,  6 Jan 2016 22:17:32 -0800	[thread overview]
Message-ID: <1452147455-26524-3-git-send-email-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <1452147455-26524-1-git-send-email-andrew.smirnov@gmail.com>

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:

> rtc_write -b <bus> -a <addr> -r 3 0x00
> hwclock

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/rtc/rtc-lib.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 1b23458..83d8045 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
--
2.5.0

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-01-07  6:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-07  6:17 [PATCH 1/6] rtc: ds1307: Add code to support ds1337/1341 Andrey Smirnov
2016-01-07  6:17 ` [PATCH 2/6] rtc: ds1307: Fix a memory leak Andrey Smirnov
2016-01-07  6:17 ` Andrey Smirnov [this message]
2016-01-07  6:57   ` [PATCH 3/6] rtc-lib: Check tm_wday for validity in rtc_valid_tm() Antony Pavlov
2016-01-07 16:54     ` Andrey Smirnov
2016-01-07  6:17 ` [PATCH 5/6] common/date.c: Fix off-by-one error Andrey Smirnov
2016-01-07  7:50   ` Sascha Hauer
2016-01-07  6:17 ` [PATCH 6/6] commands/hwclock: Check return value of rtc_read_time() Andrey Smirnov
2016-01-07  6:58   ` Antony Pavlov
2016-01-07  6:51 ` [PATCH 1/6] rtc: ds1307: Add code to support ds1337/1341 Antony Pavlov
2016-01-07  7:48 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1452147455-26524-3-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox