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/io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index 9bffe1a..0af8b02 100644 --- a/src/io.c +++ b/src/io.c @@ -454,7 +454,7 @@ void io_load_app(void) { FILE *data_file; int c, is_appointment, is_event, is_recursive; - struct tm start, end, until, *lt; + struct tm start, end, until, lt; llist_t exc; time_t t; int id = 0; @@ -463,8 +463,8 @@ void io_load_app(void) char note[MAX_NOTESIZ + 1], *notep; t = time(NULL); - lt = localtime(&t); - start = end = until = *lt; + localtime_r(&t, <); + start = end = until = lt; data_file = fopen(path_apts, "r"); EXIT_IF(data_file == NULL, _("failed to open appointment file")); -- cgit v1.2.3-54-g00ecf From e16ac0a8a8c18c831e95e1a0799e919e61f5da48 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 23 Nov 2012 10:53:37 +0100 Subject: Do not display a mark when files are auto-saved This is kind of useless since users are not able to react to an auto-save notification. It also causes all kinds of problems if the status bar is in a non-standard mode (message, prompt, ...) and is prone to race conditions if the status bar is updated by another thread at the same time. Signed-off-by: Lukas Fleischer --- src/calcurse.h | 1 - src/io.c | 24 ++---------------------- 2 files changed, 2 insertions(+), 23 deletions(-) (limited to 'src/io.c') diff --git a/src/calcurse.h b/src/calcurse.h index 7259dd1..e35fe9a 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -580,7 +580,6 @@ enum export_type { /* To customize the display when saving data. */ enum save_display { IO_SAVE_DISPLAY_BAR, - IO_SAVE_DISPLAY_MARK, IO_SAVE_DISPLAY_NONE }; diff --git a/src/io.c b/src/io.c index 0af8b02..0cc394e 100644 --- a/src/io.c +++ b/src/io.c @@ -302,23 +302,6 @@ void io_extract_data(char *dst_data, const char *org, int len) *dst_data = '\0'; } -static void display_mark(void) -{ - const int DISPLAY_TIME = 1; - WINDOW *mwin; - - mwin = newwin(1, 2, 1, col - 3); - - custom_apply_attr(mwin, ATTR_HIGHEST); - mvwaddstr(mwin, 0, 0, "**"); - wins_wrefresh(mwin); - sleep(DISPLAY_TIME); - mvwaddstr(mwin, 0, 0, " "); - wins_wrefresh(mwin); - delwin(mwin); - wins_doupdate(); -} - static pthread_mutex_t io_save_mutex = PTHREAD_MUTEX_INITIALIZER; /* @@ -412,8 +395,6 @@ void io_save_cal(enum save_display display) if (ui_mode == UI_CURSES && display == IO_SAVE_DISPLAY_BAR && conf.progress_bar) show_bar = 1; - else if (ui_mode == UI_CURSES && display == IO_SAVE_DISPLAY_MARK) - display_mark(); if (show_bar) progress_bar(PROGRESS_BAR_SAVE, PROGRESS_BAR_CONF); @@ -436,8 +417,7 @@ void io_save_cal(enum save_display display) ERROR_MSG("%s", access_pb); /* Print a message telling data were saved */ - if (ui_mode == UI_CURSES && conf.system_dialogs - && display != IO_SAVE_DISPLAY_MARK) { + if (ui_mode == UI_CURSES && conf.system_dialogs) { status_mesg(save_success, enter); wgetch(win[STA].p); } @@ -1152,7 +1132,7 @@ static void *io_psave_thread(void *arg) for (;;) { sleep(delay * MININSEC); - io_save_cal(IO_SAVE_DISPLAY_MARK); + io_save_cal(IO_SAVE_DISPLAY_NONE); } } -- cgit v1.2.3-54-g00ecf