aboutsummaryrefslogtreecommitdiffstats
path: root/src/calendar.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-11-22 22:23:58 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2012-11-22 22:58:04 +0100
commite269f09438ad1bfaef044c5781615cba45ab7690 (patch)
treec68bd062390f59525ae5cf061c131f52a513d1b7 /src/calendar.c
parent6b6067a53bd6e78215f4c39cc0d9fa2258b6e095 (diff)
downloadcalcurse-e269f09438ad1bfaef044c5781615cba45ab7690.tar.gz
calcurse-e269f09438ad1bfaef044c5781615cba45ab7690.zip
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 <baptiste@jonglez.org> Reported-by: Erik Saule <esaule@bmi.osu.edu> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/calendar.c')
-rw-r--r--src/calendar.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/calendar.c b/src/calendar.c
index a157caa..48ac84d 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -140,15 +140,15 @@ void calendar_stop_date_thread(void)
void calendar_set_current_date(void)
{
time_t timer;
- struct tm *tm;
+ struct tm tm;
timer = time(NULL);
- tm = localtime(&timer);
+ localtime_r(&timer, &tm);
pthread_mutex_lock(&date_thread_mutex);
- today.dd = tm->tm_mday;
- today.mm = tm->tm_mon + 1;
- today.yyyy = tm->tm_year + 1900;
+ today.dd = tm.tm_mday;
+ today.mm = tm.tm_mon + 1;
+ today.yyyy = tm.tm_year + 1900;
pthread_mutex_unlock(&date_thread_mutex);
}
@@ -684,16 +684,16 @@ void calendar_move(enum move move, int count)
long calendar_start_of_year(void)
{
time_t timer;
- struct tm *tm;
+ struct tm tm;
timer = time(NULL);
- tm = localtime(&timer);
- tm->tm_mon = 0;
- tm->tm_mday = 1;
- tm->tm_hour = 0;
- tm->tm_min = 0;
- tm->tm_sec = 0;
- timer = mktime(tm);
+ localtime_r(&timer, &tm);
+ tm.tm_mon = 0;
+ tm.tm_mday = 1;
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ timer = mktime(&tm);
return (long)timer;
}
@@ -701,17 +701,17 @@ long calendar_start_of_year(void)
long calendar_end_of_year(void)
{
time_t timer;
- struct tm *tm;
+ struct tm tm;
timer = time(NULL);
- tm = localtime(&timer);
- tm->tm_mon = 0;
- tm->tm_mday = 1;
- tm->tm_hour = 0;
- tm->tm_min = 0;
- tm->tm_sec = 0;
- tm->tm_year++;
- timer = mktime(tm);
+ localtime_r(&timer, &tm);
+ tm.tm_mon = 0;
+ tm.tm_mday = 1;
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ tm.tm_year++;
+ timer = mktime(&tm);
return (long)(timer - 1);
}