fgets may return a NULL pointer...
fgets can return NULL and if it returns NULL, the application
will be in an undefined state.
committer: Markus Bröker <mbroeker@largo.homelinux.org>
--- a/src/config.c
+++ b/src/config.c
@@ -46,7 +46,8 @@
uc->port = 6667;
while (!feof (f)) {
- (void)fgets (buffer, sizeof (buffer), f);
+ if (fgets (buffer, sizeof (buffer), f) == NULL)
+ break;
token = buffer;
while (*token == '\t') /* Eat trailing tabs */
--- a/src/irc.c
+++ b/src/irc.c
@@ -106,7 +106,8 @@
fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
for (;;) {
- fgets (msg, sizeof (msg), stream);
+ if (fgets (msg, sizeof (msg), stream) == NULL)
+ break;
if ((user = irc_parsemessage (msg, &message)) != NULL)
printf ("%10s %s\n", user, message.line);
--- a/src/main.c
+++ b/src/main.c
@@ -92,7 +92,8 @@
}
while (!feof (message.stream)) {
- fgets (buf, sizeof (buf), message.stream);
+ if (fgets (buf, sizeof (buf), message.stream) == NULL)
+ break;
if (!active) /* the bot was killed with SIGTERM */
break;