]> err.no Git - linux-2.6/commitdiff
[PATCH] RTC class: error checks
authorDavid Brownell <david-b@pacbell.net>
Sun, 1 Oct 2006 06:28:16 +0000 (23:28 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sun, 1 Oct 2006 07:39:25 +0000 (00:39 -0700)
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>
drivers/rtc/rtc-lib.c
drivers/rtc/rtc-proc.c

index 9812120f3a7c825c783a7c15635279740ced383d..ba795a4db1e97289829c3c69dbee613fa2720a25 100644 (file)
@@ -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;
index 1b2c2caa2a99e9b1d2290f4a1b2c7d3dafea9ef2..2943d83edfd161c07e924155a75e8ec6867309b2 100644 (file)
@@ -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");