Fix security unittest regarding iotvticalendartest on 32 bit OS
authorjs126.lee <js126.lee@samsung.com>
Thu, 7 Jan 2016 06:40:36 +0000 (15:40 +0900)
committerDmitriy Zhuravlev <d.zhuravlev@samsung.com>
Tue, 12 Jan 2016 13:23:06 +0000 (13:23 +0000)
-issue : IsRequestWithinValidTimeTest.IsRequestWithinValidTimeValidPeriod1 is failed on 32 bit OS
-reason : On 32 bit OS, integer overflow occur in return of mktime due to Year 2038 problem,
        when Checking whether endDateTime is after startDateTime in iotvticalendar.c
-solution : Checking the period using tm structure members instead of mktime and difftime function.

-Patch#5 : Split long lines

Change-Id: I5bb14336573ee8b7d42dbbe4f3c45af44f937c3e
Signed-off-by: js126.lee <js126.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4765
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Andrii Shtompel <a.shtompel@samsung.com>
Reviewed-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
resource/csdk/security/src/iotvticalendar.c [changed mode: 0644->0755]
resource/csdk/security/unittest/iotvticalendartest.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index d65578a..0692cd9
@@ -98,22 +98,32 @@ IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period)
         if(NULL != strptime(endDTPos, fmt, &period->endDateTime))
         {
             //Checking if endDateTime is after startDateTime
-            if(difftime(mktime(&period->endDateTime),
-                        mktime(&period->startDateTime)) > 0)
+            if ((period->startDateTime.tm_year > period->endDateTime.tm_year)
+                || ((period->startDateTime.tm_year == period->endDateTime.tm_year)
+                    && (period->startDateTime.tm_mon > period->endDateTime.tm_mon))
+                || ((period->startDateTime.tm_year == period->endDateTime.tm_year)
+                    && (period->startDateTime.tm_mon == period->endDateTime.tm_mon)
+                    && (period->startDateTime.tm_mday > period->endDateTime.tm_mday))
+                || (( fmt == dtFormat) && (period->startDateTime.tm_year == period->endDateTime.tm_year)
+                    && (period->startDateTime.tm_mon == period->endDateTime.tm_mon)
+                    && (period->startDateTime.tm_mday == period->endDateTime.tm_mday)
+                    && (period->startDateTime.tm_hour > period->endDateTime.tm_hour))
+                || (( fmt == dtFormat) && (period->startDateTime.tm_year == period->endDateTime.tm_year)
+                    && (period->startDateTime.tm_mon == period->endDateTime.tm_mon)
+                    && (period->startDateTime.tm_mday == period->endDateTime.tm_mday)
+                    && (period->startDateTime.tm_hour == period->endDateTime.tm_hour)
+                    && (period->startDateTime.tm_min > period->endDateTime.tm_min))
+                || (( fmt == dtFormat) && (period->startDateTime.tm_year == period->endDateTime.tm_year)
+                    && (period->startDateTime.tm_mon == period->endDateTime.tm_mon)
+                    && (period->startDateTime.tm_mday == period->endDateTime.tm_mday)
+                    && (period->startDateTime.tm_hour == period->endDateTime.tm_hour)
+                    && (period->startDateTime.tm_min == period->endDateTime.tm_min)
+                    && (period->startDateTime.tm_sec > period->endDateTime.tm_sec)))
+            {
+                return IOTVTICAL_INVALID_PERIOD;
+            }
+            else
             {
-                //mktime increases value of tm_hour by 1 if tm_isdst is set.
-                //The tm_hour value in period's startDateTime and endDatetime
-                //should remain same irrespective of daylight saving time.
-                if(period->startDateTime.tm_isdst)
-                {
-                    period->startDateTime.tm_hour =
-                   (period->startDateTime.tm_hour + TOTAL_HOURS - TM_DST_OFFSET) % TOTAL_HOURS;
-                }
-                if(period->endDateTime.tm_isdst)
-                {
-                    period->endDateTime.tm_hour =
-                   (period->endDateTime.tm_hour + TOTAL_HOURS - TM_DST_OFFSET) % TOTAL_HOURS;
-                }
                 return IOTVTICAL_SUCCESS;
             }
         }