projects/linux·commit db621f17

[PATCH] RTC class: error checks

db621f17 · David Brownell <[email protected]> · 2006-09-30 23:28:16 -07:00

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 <[email protected]>
Cc: Alessandro Zummo <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Commit
db621f174d2c017d960089ea8cbc91c0763f1069
Parents
818a8674

Changes

2 files changed · +5 −5

FileStatusAddDelContent
drivers/rtc/rtc-lib.cmodified+4−4View file
drivers/rtc/rtc-proc.cmodified+1−1View file

drivers/rtc/rtc-lib.c

View file
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 9812120..ba795a4 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -94,12 +94,12 @@ EXPORT_SYMBOL(rtc_time_to_tm);
int rtc_valid_tm(struct rtc_time *tm)
{
if (tm->tm_year < 70
- || tm->tm_mon >= 12
+ || ((unsigned)tm->tm_mon) >= 12
|| tm->tm_mday < 1
|| tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900)
- || tm->tm_hour >= 24
- || tm->tm_min >= 60
- || tm->tm_sec >= 60)
+ || ((unsigned)tm->tm_hour) >= 24
+ || ((unsigned)tm->tm_min) >= 60
+ || ((unsigned)tm->tm_sec) >= 60)
return -EINVAL;
return 0;

drivers/rtc/rtc-proc.c

View file
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index 1b2c2ca..2943d83 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -61,7 +61,7 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
else
seq_printf(seq, "**-");
- if ((unsigned int)alrm.time.tm_mday <= 31)
+ if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
seq_printf(seq, "%02d\n", alrm.time.tm_mday);
else
seq_printf(seq, "**\n");