aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Wildenhain <benedikt.wildenhain@hs-bochum.de>2023-08-12 17:26:40 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2023-11-05 14:14:51 -0500
commit535088c8096b028d3c0c3ceaf7b49aeec4258fa1 (patch)
tree4b33e818d4a03eea6357f935a7a10d67da9b3f2a
parent95bb55f68b446e4461f27ef3a74a7d2eda950289 (diff)
downloadcalcurse-535088c8096b028d3c0c3ceaf7b49aeec4258fa1.tar.gz
calcurse-535088c8096b028d3c0c3ceaf7b49aeec4258fa1.zip
Fix segmentation fault when exporting ical file
If a note file gets accidently deleted this leads to ical_export_note trying to execute fclose(NULL) which leads to a segmentation fault on current Debian GNU/Linux using libc6 (according to fclose's manpage, the behaviour is undefined in this case). The fix tests whether fopen returned a non-NULL-pointer before trying to close it. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/ical.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/ical.c b/src/ical.c
index 4a7738e..6d2d8d2 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -214,7 +214,8 @@ static void ical_export_note(FILE *stream, char *name)
asprintf(&note_file, "%s/%s", path_notes, name);
if (!(fp = fopen(note_file, "r")) || ungetc(getc(fp), fp) == EOF) {
- fclose(fp);
+ if (fp)
+ fclose(fp);
return;
}
string_init(&note);