Skip to content

Commit e74a8f2

Browse files
bwhackstorvalds
authored andcommitted
drivers/rtc/interface.c: fix alarm rollover when day or month is out-of-range
Commit f44f7f9 ("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]>
1 parent 948170f commit e74a8f2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/rtc/interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
228228
alarm->time.tm_hour = now.tm_hour;
229229

230230
/* For simplicity, only support date rollover for now */
231-
if (alarm->time.tm_mday == -1) {
231+
if (alarm->time.tm_mday < 1 || alarm->time.tm_mday > 31) {
232232
alarm->time.tm_mday = now.tm_mday;
233233
missing = day;
234234
}
235-
if (alarm->time.tm_mon == -1) {
235+
if ((unsigned)alarm->time.tm_mon >= 12) {
236236
alarm->time.tm_mon = now.tm_mon;
237237
if (missing == none)
238238
missing = month;

0 commit comments

Comments
 (0)