From 3412e2cfc145e7bc5d7d19368023564016215fcf Mon Sep 17 00:00:00 2001 From: Radoslaw Czerski Date: Tue, 12 Apr 2016 18:10:13 +0200 Subject: modules/clock: Use of vulnerable function fixed. localetime -> localetime_r Change-Id: Icd77548776d1ba5b4f15c79b6c1aa0119b83fc86 Signed-off-by: Radoslaw Czerski --- src/modules/clock/clock.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/modules') diff --git a/src/modules/clock/clock.c b/src/modules/clock/clock.c index d8c1472..f7a70ec 100644 --- a/src/modules/clock/clock.c +++ b/src/modules/clock/clock.c @@ -163,7 +163,7 @@ static void indicator_clock_changed_cb(void *data) char result[CLOCK_STR_LEN] = {0,}; char icu_apm[CLOCK_STR_LEN] = {0,}; - struct tm *ts = NULL; + struct tm ts; time_t ctime; struct appdata *ad = NULL; int len; @@ -178,8 +178,10 @@ static void indicator_clock_changed_cb(void *data) /* Set time */ ctime = time(NULL); - ts = localtime(&ctime); - if (ts == NULL) { + + errno = 0; + localtime_r(&ctime, &ts); + if (errno != 0) { _E("Fail to get localtime !"); return; } @@ -195,7 +197,7 @@ static void indicator_clock_changed_cb(void *data) memset(ampm_buf, 0x00, sizeof(ampm_buf)); memset(buf, 0x00, sizeof(buf)); - clock_timer = ecore_timer_add(60 - ts->tm_sec, (void *)indicator_clock_changed_cb, data); + clock_timer = ecore_timer_add(60 - ts.tm_sec, (void *)indicator_clock_changed_cb, data); if(!clock_timer) { _E("Fail to add timer !"); } @@ -210,7 +212,7 @@ static void indicator_clock_changed_cb(void *data) static int pre_hour = 0; if (apm_length>=4) { - if (ts->tm_hour >= 0 && ts->tm_hour < 12) { + if (ts.tm_hour >= 0 && ts.tm_hour < 12) { snprintf(ampm_buf, sizeof(ampm_buf),"%s","AM"); } else { snprintf(ampm_buf, sizeof(ampm_buf),"%s","PM"); @@ -219,9 +221,9 @@ static void indicator_clock_changed_cb(void *data) snprintf(ampm_buf, sizeof(ampm_buf),"%s",icu_apm); } - strftime(bf1, sizeof(bf1), "%l", ts); + strftime(bf1, sizeof(bf1), "%l", &ts); hour = atoi(bf1); - strftime(bf1, sizeof(bf1), ":%M", ts); + strftime(bf1, sizeof(bf1), ":%M", &ts); font_size = TIME_FONT_SIZE_12; clock_hour = hour; -- cgit v1.2.3