Skip to content

Commit db621f1

Browse files
David BrownellLinus Torvalds
authored andcommitted
[PATCH] RTC class: error checks
The rtc_is_valid_tm() routine needs to treat some of the fields it checks as unsigned, to prevent wrongly accepting invalid rtc_time structs; this is the same approach used elsewhere in the RTC code for such tests. Conversely, rtc_proc_show() is missing one invalid-day-of-month test that rtc_is_valid_tm() makes: there is no day zero. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 818a867 commit db621f1

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎drivers/rtc/rtc-lib.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ EXPORT_SYMBOL(rtc_time_to_tm);
9494
int rtc_valid_tm(struct rtc_time *tm)
9595
{
9696
if (tm->tm_year < 70
97-
|| tm->tm_mon >= 12
97+
|| ((unsigned)tm->tm_mon) >= 12
9898
|| tm->tm_mday < 1
9999
|| tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900)
100-
|| tm->tm_hour >= 24
101-
|| tm->tm_min >= 60
102-
|| tm->tm_sec >= 60)
100+
|| ((unsigned)tm->tm_hour) >= 24
101+
|| ((unsigned)tm->tm_min) >= 60
102+
|| ((unsigned)tm->tm_sec) >= 60)
103103
return -EINVAL;
104104

105105
return 0;

‎drivers/rtc/rtc-proc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
6161
seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
6262
else
6363
seq_printf(seq, "**-");
64-
if ((unsigned int)alrm.time.tm_mday <= 31)
64+
if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
6565
seq_printf(seq, "%02d\n", alrm.time.tm_mday);
6666
else
6767
seq_printf(seq, "**\n");

0 commit comments

Comments
 (0)