aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Johnson <nick@nicksphere.ch>2022-08-11 00:00:00 +0000
committerLukas Fleischer <lfleischer@calcurse.org>2023-01-31 19:27:57 -0500
commit4cd300f2c408907b4a576b55fc15479afbd5d81f (patch)
tree37424e537fb41cce37e0a978cdf0b7813dc7b6d9
parentac5113640d742c105271a19343d709d5a4f6718c (diff)
downloadcalcurse-4cd300f2c408907b4a576b55fc15479afbd5d81f.tar.gz
calcurse-4cd300f2c408907b4a576b55fc15479afbd5d81f.zip
Check that note files open before reading them
This fixes the scenario where a note file referenced by a todo, event, or appointment is modified from outside the program in such a way that it cannot be opened by the program, resulting in a segmentation fault. The least surprising way to proceed is to ignore the note. Signed-off-by: Nicholas Johnson <nick@nicksphere.ch> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/day.c8
-rw-r--r--src/ui-todo.c5
2 files changed, 13 insertions, 0 deletions
diff --git a/src/day.c b/src/day.c
index a86a91d..13149ea 100644
--- a/src/day.c
+++ b/src/day.c
@@ -634,6 +634,10 @@ void day_popup_item(struct day_item *day)
asprintf(&notepath, "%s%s", path_notes, day_item_get_note(day));
fp = fopen(notepath, "r");
+ if (fp == NULL) {
+ item_in_popup(NULL, NULL, day_item_get_mesg(day), _("Event:"));
+ return;
+ }
note_read_contents(note, note_size, fp);
fclose(fp);
mem_free(notepath);
@@ -661,6 +665,10 @@ void day_popup_item(struct day_item *day)
asprintf(&notepath, "%s%s", path_notes, day_item_get_note(day));
fp = fopen(notepath, "r");
+ if (fp == NULL) {
+ item_in_popup(a_st, a_end, day_item_get_mesg(day), _("Appointment:"));
+ return;
+ }
note_read_contents(note, note_size, fp);
fclose(fp);
mem_free(notepath);
diff --git a/src/ui-todo.c b/src/ui-todo.c
index b65b8d3..6fdd08f 100644
--- a/src/ui-todo.c
+++ b/src/ui-todo.c
@@ -327,6 +327,11 @@ void ui_todo_popup_item(void)
asprintf(&notepath, "%s%s", path_notes, item->note);
fp = fopen(notepath, "r");
+ if (fp == NULL) {
+ item_in_popup(NULL, NULL, item->mesg, _("TODO:"));
+ return;
+ }
+
note_read_contents(note, note_size, fp);
fclose(fp);
mem_free(notepath);