🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #945

Possible NNTP 1.5.10 bug

#945
From: Steve Groom
Date: Thu, 31 Jan 1991 21:39
54 lines
2715 bytes
I found this in the NNTP 1.5.10 server/serve.c source.  I don't know if it's
been discussed before.

----- server/serve.c, line 256
    #ifdef TIMEOUT
                /* Do timeout with select() (i.e. the intelligent way) */
                FD_ZERO(&readfds); 
                FD_SET(fileno(stdin), &readfds);
                errno = 0;
***>            i = select(fileno(stdin) + 1,
                    &readfds, (fd_set*)0, (fd_set*)0, &timeout);
                if (i < 0) {
                        /* "Interrupted system call" isn't a real error */
                        if (errno == EINTR)
                                continue;
                        syslog(LOG_ERR, "%s read select: %m", hostname);
                        break;
                }
                if (!FD_ISSET(fileno(stdin), &readfds)) {
                        printf(    
                    "%d Timeout after %d seconds, closing connection.\r\n",
                                ERR_FAULT, TIMEOUT);
                        (void) fflush(stdout);

    #ifdef LOG
                        syslog(LOG_ERR, "%s timeout", hostname);
    #endif LOG
                        exit(1); 
                }
    #endif   
***>            if (fgets(line, sizeof(line), stdin) == NULL)
                        break;


--------------------

The problem:  You shouldn't use select() to determine if stdin is ready to
for reading.  There may be characters in the stdio buffer for stdin
that have not yet been read, and this code only uses select() to look
at the file descriptor.  If so, the select() may time out even though
stdin could have been successfully read.  

In reality, stdin is usually line buffered so it's not that big a deal,
because at this point in the code we're looking to read a whole new
line.

It doesn't look like an easy problem to do right, but this solution looks
like it might cause problems.

-steve
-- 
Steve Groom, Jet Propulsion Laboratory, Pasadena, CA
stevo@elroy.jpl.nasa.gov  {ames,usc}!elroy!stevo
Technical Details
Message-ID: <1991Jan31.213914.21852@elroy.jpl.nasa.gov>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!news

Show Full Headers
Complete Article Headers
Message-ID: <1991Jan31.213914.21852@elroy.jpl.nasa.gov>
Subject: Possible NNTP 1.5.10 bug
Date: Thu, 31 Jan 1991 21:39:14 +0000
From: stevo@elroy.jpl.nasa.gov (Steve Groom)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!news
Newsgroups: news.software.nntp
Sender: news@elroy.jpl.nasa.gov (Usenet)
Organization: Image Analysis Systems Group, JPL
Lines: 53
Originator: stevo@uniblab
Nntp-Posting-Host: uniblab.jpl.nasa.gov