From e269f09438ad1bfaef044c5781615cba45ab7690 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 22 Nov 2012 22:23:58 +0100 Subject: Replace localtime() with localtime_r() Since the result of localtime() is stored in a statically allocated structure, data was overwritten when a context switch occurred during (or shortly after) the execution of localtime(), potentially resulting in critical data corruption. BUG#7 and BUG#8 are likely related. This patch converts all usages of localtime() with localtime_r(), which is thread-safe. Reported-by: Baptiste Jonglez Reported-by: Erik Saule Signed-off-by: Lukas Fleischer --- src/notify.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/notify.c') diff --git a/src/notify.c b/src/notify.c index a057c2f..10bc0f7 100644 --- a/src/notify.c +++ b/src/notify.c @@ -310,18 +310,18 @@ static void *notify_main_thread(void *arg) const unsigned check_app = MININSEC; int elapse = 0; int got_app; - struct tm *ntime; + struct tm ntime; time_t ntimer; elapse = 0; for (;;) { ntimer = time(NULL); - ntime = localtime(&ntimer); + localtime_r(&ntimer, &ntime); pthread_mutex_lock(¬ify.mutex); pthread_mutex_lock(&nbar.mutex); - strftime(notify.time, NOTIFY_FIELD_LENGTH, nbar.timefmt, ntime); - strftime(notify.date, NOTIFY_FIELD_LENGTH, nbar.datefmt, ntime); + strftime(notify.time, NOTIFY_FIELD_LENGTH, nbar.timefmt, &ntime); + strftime(notify.date, NOTIFY_FIELD_LENGTH, nbar.datefmt, &ntime); pthread_mutex_unlock(&nbar.mutex); pthread_mutex_unlock(¬ify.mutex); notify_update_bar(); -- cgit v1.2.3-54-g00ecf