fgets may return a NULL pointer...
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Mon, 22 Feb 2010 19:06:15 +0100
changeset 47 a689b6a8e6ed
parent 46 08ad49ca1b4e
child 48 34094173351c
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>
src/config.c
src/irc.c
src/main.c
--- 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;