Skip to content

Commit

Permalink
Fix segmentation fault when exporting ical file
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bwildenhain authored and Lukas Fleischer committed Nov 5, 2023
1 parent 95bb55f commit 535088c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ical.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 535088c

Please sign in to comment.