summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-02-17 16:49:35 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2012-02-18 13:04:21 +0100
commit894ac2d70dd2ab3a8db709409389cc1a83385eb5 (patch)
tree3141866abbb7c5c72f909aa5516f10dced1f7be1
parent47ceb96e1356ce369931c127c33266e863e61c89 (diff)
downloadcalcurse-894ac2d70dd2ab3a8db709409389cc1a83385eb5.tar.gz
calcurse-894ac2d70dd2ab3a8db709409389cc1a83385eb5.zip
Trap fgets() failure in *_scan()
Ensure we don't read arbitrary data when fgets() returns a NULL string (meaning that either the EOF is encountered or an error occurred). This also fixes a couple of compiler warnings seen with "-Wunused-result". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/apoint.c4
-rw-r--r--src/event.c4
-rw-r--r--src/recur.c8
3 files changed, 12 insertions, 4 deletions
diff --git a/src/apoint.c b/src/apoint.c
index 4796ae9..5813e42 100644
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -443,7 +443,9 @@ apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
localtime (&t);
/* Read the appointment description */
- fgets (buf, sizeof buf, f);
+ if (!fgets (buf, sizeof buf, f))
+ return NULL;
+
newline = strchr (buf, '\n');
if (newline)
*newline = '\0';
diff --git a/src/event.c b/src/event.c
index 64bc3eb..4e1292b 100644
--- a/src/event.c
+++ b/src/event.c
@@ -149,7 +149,9 @@ event_scan (FILE *f, struct tm start, int id, char *note)
localtime (&t);
/* Read the event description */
- fgets (buf, sizeof buf, f);
+ if (!fgets (buf, sizeof buf, f))
+ return NULL;
+
nl = strchr (buf, '\n');
if (nl)
{
diff --git a/src/recur.c b/src/recur.c
index b373b11..79046f8 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -374,7 +374,9 @@ recur_apoint_scan (FILE *f, struct tm start, struct tm end, char type,
time_t tstart, tend, tuntil;
/* Read the appointment description */
- fgets (buf, sizeof buf, f);
+ if (!fgets (buf, sizeof buf, f))
+ return NULL;
+
nl = strchr (buf, '\n');
if (nl)
{
@@ -419,7 +421,9 @@ recur_event_scan (FILE *f, struct tm start, int id, char type, int freq,
time_t tstart, tuntil;
/* Read the event description */
- fgets (buf, sizeof buf, f);
+ if (!fgets (buf, sizeof buf, f))
+ return NULL;
+
nl = strchr (buf, '\n');
if (nl)
{