shared: Fix issue with pointer casting on 64bit system 08/175908/3
authorWook Song <wook16.song@samsung.com>
Fri, 13 Apr 2018 06:29:54 +0000 (15:29 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 16 Apr 2018 04:41:50 +0000 (13:41 +0900)
The type casting from the pointer of a signed int value to the pointer
of a signed long value (time_t, especially in this patch) could provide
unintended result in 64bit system. This patch fixes this issue related
to using the localtime/localtime_r function.

Change-Id: Ief46cc079a64e628c1219dc7638a494264583af5
Signed-off-by: Wook Song <wook16.song@samsung.com>
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
src/shared/logprint.c

index efd6c5e..6860635 100644 (file)
@@ -608,6 +608,7 @@ char *log_format_log_line(
        struct tm tmBuf;
 #endif
        struct tm* ptm;
+       time_t time_t_temp;
        char timeBuf[32], tzBuf[16];
        char recvTimeBuf[32];
        char prefixBuf[128], suffixBuf[128];
@@ -630,17 +631,19 @@ char *log_format_log_line(
         * in the time stamp.  Don't use forward slashes, parenthesis,
         * brackets, asterisks, or other special chars here.
         */
+       time_t_temp = (time_t)entry->sec;
 #if defined(HAVE_LOCALTIME_R)
-       ptm = localtime_r((const time_t*)&(entry->sec), &tmBuf);
+       ptm = localtime_r((const time_t*)&time_t_temp, &tmBuf);
 #else
-       ptm = localtime((const time_t*)&(entry->sec));
+       ptm = localtime((const time_t*)&time_t_temp);
 #endif
        strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm);
 
+       time_t_temp = (time_t)entry->sec_recv_real;
 #if defined(HAVE_LOCALTIME_R)
-       ptm = localtime_r((const time_t*)&(entry->sec_recv_real), &tmBuf);
+       ptm = localtime_r((const time_t*)&time_t_temp, &tmBuf);
 #else
-       ptm = localtime((const time_t*)&(entry->sec_recv_real));
+       ptm = localtime((const time_t*)&time_t_temp);
 #endif
        strftime(recvTimeBuf, sizeof(recvTimeBuf), "%m-%d %H:%M:%S", ptm);