drivers/rtc/interface.c: fix alarm rollover when day or month is out-of-range
authorBen Hutchings <[email protected]>
Tue, 10 Jan 2012 23:11:02 +0000 (15:11 -0800)
committerLinus Torvalds <[email protected]>
Wed, 11 Jan 2012 00:30:53 +0000 (16:30 -0800)
Commit f44f7f96a20a ("RTC: Initialize kernel state from RTC") introduced a
potential infinite loop.  If an alarm time contains a wildcard month and
an invalid day (> 31), or a wildcard year and an invalid month (>= 12),
the loop searching for the next matching date will never terminate.  Treat
the invalid values as wildcards.

Fixes <http://bugs.debian.org/646429>, <http://bugs.debian.org/653331>

Reported-by: leo weppelman <[email protected]>
Reported-by: "P. van Gaans" <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
Signed-off-by: Jonathan Nieder <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Marcelo Roberto Jimenez <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: John Stultz <[email protected]>
Acked-by: Alessandro Zummo <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
drivers/rtc/interface.c

index 8e286259a007fbc5921b4c569cdb959f62762f7a..8a1c031391d66f00a2c276325841bea20546e3c4 100644 (file)
@@ -228,11 +228,11 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
                alarm->time.tm_hour = now.tm_hour;
 
        /* For simplicity, only support date rollover for now */
-       if (alarm->time.tm_mday == -1) {
+       if (alarm->time.tm_mday < 1 || alarm->time.tm_mday > 31) {
                alarm->time.tm_mday = now.tm_mday;
                missing = day;
        }
-       if (alarm->time.tm_mon == -1) {
+       if ((unsigned)alarm->time.tm_mon >= 12) {
                alarm->time.tm_mon = now.tm_mon;
                if (missing == none)
                        missing = month;