diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2012-11-22 22:23:58 +0100 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2012-11-22 22:58:04 +0100 |
commit | e269f09438ad1bfaef044c5781615cba45ab7690 (patch) | |
tree | c68bd062390f59525ae5cf061c131f52a513d1b7 /src/event.c | |
parent | 6b6067a53bd6e78215f4c39cc0d9fa2258b6e095 (diff) | |
download | 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/event.c')
-rw-r--r-- | src/event.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/event.c b/src/event.c index f460ded..203af44 100644 --- a/src/event.c +++ b/src/event.c @@ -112,13 +112,13 @@ unsigned event_inday(struct event *i, long start) /* Write to file the event in user-friendly format */ void event_write(struct event *o, FILE * f) { - struct tm *lt; + struct tm lt; time_t t; t = o->day; - lt = localtime(&t); - fprintf(f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday, - 1900 + lt->tm_year, o->id); + localtime_r(&t, <); + fprintf(f, "%02u/%02u/%04u [%d] ", lt.tm_mon + 1, lt.tm_mday, + 1900 + lt.tm_year, o->id); if (o->note != NULL) fprintf(f, ">%s ", o->note); fprintf(f, "%s\n", o->mesg); @@ -128,10 +128,7 @@ void event_write(struct event *o, FILE * f) struct event *event_scan(FILE * f, struct tm start, int id, char *note) { char buf[BUFSIZ], *nl; - time_t tstart, t; - - t = time(NULL); - localtime(&t); + time_t tstart; /* Read the event description */ if (!fgets(buf, sizeof buf, f)) |