Problem in server/tcpserver.c

Peter F Bradshaw <[email protected]> Fri, 26 Apr 2002 14:55:31 +0800 (WST)
Newsgroups gmane.network.gnunet.bugs
Message-ID <Pine.LNX.4.44.0204261440130.4647-100000@goldmund>
Hi;

I'm running the CVS source of this date. There is an endless loop
in processData(). This seems to occur as the result of some searchs
(i.e. gnunet-search).

Lines from 105 read:

   while (pos < sizeof(GPROXY_Message)) {
    n = read(sockDescriptor,
      &((char*)&buff)[pos],
      sizeof(GPROXY_Message)-pos);
    if (n < 0)
      break;
    pos += n;
    }

In some instances the read() is returning 0 which sets up an endless
loop. In the normal blocking case a return of 0 from read() indicates
EOF. Therefore, I think the code should be:

    while (pos < sizeof(GPROXY_Message)) {
      n = read(sockDescriptor,
	       &((char*)&buff)[pos],
	       sizeof(GPROXY_Message)-pos);
      if (n < 0)
	      break;
      else if (n == 0)
        return;
      pos += n;
    }

Cheers

-- 
Peter F Bradshaw, [email protected], ICQ 75431157 (exadios).
http://www.exadios.com
PGP public key at http://www.exadios.com/public_key.html
"Needs more salt" - Archimedes