Commit e74a8f2e authored by Ben Hutchings's avatar Ben Hutchings Committed by Linus Torvalds

drivers/rtc/interface.c: fix alarm rollover when day or month is out-of-range

Commit f44f7f96 ("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: default avatarleo weppelman <leoweppelman@googlemail.com>
Reported-by: default avatar"P. van Gaans" <mailme667@yahoo.co.uk>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarJonathan Nieder <jrnieder@gmail.com>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Acked-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 948170f8
...@@ -228,11 +228,11 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -228,11 +228,11 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
alarm->time.tm_hour = now.tm_hour; alarm->time.tm_hour = now.tm_hour;
/* For simplicity, only support date rollover for now */ /* 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; alarm->time.tm_mday = now.tm_mday;
missing = day; missing = day;
} }
if (alarm->time.tm_mon == -1) { if ((unsigned)alarm->time.tm_mon >= 12) {
alarm->time.tm_mon = now.tm_mon; alarm->time.tm_mon = now.tm_mon;
if (missing == none) if (missing == none)
missing = month; missing = month;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment