0001-Don-t-fclose-fp-if-it-failed-to-fopen.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. From dc63cf73781f9303ed1f12dc7e4ecfb6f3938f3c Mon Sep 17 00:00:00 2001
  2. From: dave <dave@slackbuilds.org>
  3. Date: Sat, 28 Jan 2023 01:51:55 +0000
  4. Subject: [PATCH] Don't fclose(fp) if it failed to fopen()
  5. MIME-Version: 1.0
  6. Content-Type: multipart/mixed; boundary="------------true"
  7. This is a multi-part message in MIME format.
  8. --------------true
  9. Content-Type: text/plain; charset=UTF-8; format=fixed
  10. Content-Transfer-Encoding: 8bit
  11. This fixes a segfault in fclose@@GLIBC_2.2.5
  12. 'calcurse -c /path/to/apts -G' segfaults at first note seen.
  13. Split the tests @ ical.c:216 into two:
  14. return if fopen(fp) failed.
  15. fclose(fp) and return @ EOF.
  16. Signed-off-by: dave <dave@slackbuilds.org>
  17. ---
  18. src/ical.c | 5 ++++-
  19. 1 file changed, 4 insertions(+), 1 deletion(-)
  20. --------------true
  21. Content-Type: text/x-patch; name="0001-Don-t-fclose-fp-if-it-failed-to-fopen.patch"
  22. Content-Transfer-Encoding: 8bit
  23. Content-Disposition: attachment; filename="0001-Don-t-fclose-fp-if-it-failed-to-fopen.patch"
  24. diff --git a/src/ical.c b/src/ical.c
  25. index 535bca8..4b55343 100644
  26. --- a/src/ical.c
  27. +++ b/src/ical.c
  28. @@ -213,7 +213,10 @@ static void ical_export_note(FILE *stream, char *name)
  29. int has_desc, has_prop, i;
  30. asprintf(&note_file, "%s/%s", path_notes, name);
  31. - if (!(fp = fopen(note_file, "r")) || ungetc(getc(fp), fp) == EOF) {
  32. + if (!(fp = fopen(note_file, "r"))) {
  33. + return;
  34. + }
  35. + if (ungetc(getc(fp), fp) == EOF) {
  36. fclose(fp);
  37. return;
  38. }
  39. --------------true--