# HG changeset patch # User Markus Bröker # Date 1266861975 -3600 # Node ID a689b6a8e6ed34d19201170d89afff5bd3759a1d # Parent 08ad49ca1b4e2051551ec69791f2c69cb406cf9f 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 diff --git a/src/config.c b/src/config.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 */ diff --git a/src/irc.c b/src/irc.c --- 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); diff --git a/src/main.c b/src/main.c --- 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;