aboutsummaryrefslogtreecommitdiffstats
path: root/src/day.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/day.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/day.c')
-rw-r--r--src/day.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/day.c b/src/day.c
index e013df5..29c03e4 100644
--- a/src/day.c
+++ b/src/day.c
@@ -730,7 +730,7 @@ static void update_rept(struct rpt **rpt, const long start)
newuntil = 0;
date_entered = 1;
} else {
- struct tm *lt;
+ struct tm lt;
time_t t;
struct date new_date;
int newmonth, newday, newyear;
@@ -738,11 +738,11 @@ static void update_rept(struct rpt **rpt, const long start)
if (parse_date(timstr, conf.input_datefmt, &newyear, &newmonth,
&newday, calendar_get_slctd_day())) {
t = start;
- lt = localtime(&t);
+ localtime_r(&t, &lt);
new_date.dd = newday;
new_date.mm = newmonth;
new_date.yyyy = newyear;
- newuntil = date2sec(new_date, lt->tm_hour, lt->tm_min);
+ newuntil = date2sec(new_date, lt.tm_hour, lt.tm_min);
if (newuntil < start) {
status_mesg(msg_wrong_time, msg_enter);
wgetch(win[STA].p);