From 894ac2d70dd2ab3a8db709409389cc1a83385eb5 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 17 Feb 2012 16:49:35 +0100 Subject: 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 --- src/apoint.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/apoint.c') 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'; -- cgit v1.2.3-54-g00ecf