Add code for checking YEAR 2038 problem 21/165321/1
authorInkyun Kil <inkyun.kil@samsung.com>
Thu, 28 Dec 2017 02:35:24 +0000 (11:35 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Thu, 28 Dec 2017 06:58:13 +0000 (15:58 +0900)
Change-Id: I25a3e905c56b78fa46b0972472b0b8a9d6af3ea0
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
alarm-manager-schedule.c

index 2956886..8206491 100644 (file)
@@ -242,8 +242,15 @@ static time_t __alarm_next_duetime_repeat(__alarm_info_t *__alarm_info)
                due_time = mktime(&duetime_tm);
        }
 
-       while (__alarm_info->start > due_time || current_time > due_time || ((!is_time_changed) && (current_time == due_time)))
+       while (__alarm_info->start > due_time || current_time > due_time || ((!is_time_changed) && (current_time == due_time))) {
+               if (due_time + alarm_info->mode.u_interval.interval < due_time) {
+                       ALARM_MGR_LOG_PRINT("time_t OVERFLOW!! duetime = %d", due_time);
+                       due_time = -1;
+                       break;
+               }
+
                due_time += alarm_info->mode.u_interval.interval;
+       }
 
        localtime_r(&due_time, &duetime_tm);
 
@@ -255,7 +262,6 @@ static time_t __alarm_next_duetime_repeat(__alarm_info_t *__alarm_info)
        start->sec = duetime_tm.tm_sec;
 
        return due_time;
-
 }
 
 static time_t __alarm_next_duetime_annually(__alarm_info_t *__alarm_info)
@@ -284,6 +290,10 @@ static time_t __alarm_next_duetime_annually(__alarm_info_t *__alarm_info)
        while (__alarm_info->start > due_time || current_time > due_time || ((!is_time_changed) && (current_time == due_time))) {
                duetime_tm.tm_year += 1;
                due_time = mktime(&duetime_tm);
+               if (due_time < 0) {
+                       ALARM_MGR_LOG_PRINT("time_t OVERFLOW!! duetime = %d", due_time);
+                       break;
+               }
        }
 
        return due_time;
@@ -321,6 +331,10 @@ static time_t __alarm_next_duetime_monthly(__alarm_info_t *__alarm_info)
                        duetime_tm.tm_year += 1;
                }
                due_time = mktime(&duetime_tm);
+               if (due_time < 0) {
+                       ALARM_MGR_LOG_PRINT("time_t OVERFLOW!! duetime = %d", due_time);
+                       break;
+               }
        }
 
        return due_time;