From: Nick Mathewson Date: Fri, 11 Sep 2009 18:21:37 +0000 (+0000) Subject: Treat a negative number of bytes to read as the kernel saying "I don't know." X-Git-Tag: release-2.0.3-alpha~112 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b461a6d03927220eae00e232d26053c71afd60f;p=libevent Treat a negative number of bytes to read as the kernel saying "I don't know." svn:r1426 --- diff --git a/ChangeLog b/ChangeLog index cb4900af..fa69e4a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,7 +17,7 @@ Changes in 2.0.3-alpha: o Support sendfile on Solaris: patch from Caitlin Mercer. o New functions to explicitly reference a socket used by an evhttp object. Patches from David Reiss. o When we send a BEV_EVENT_CONNECTED to indicate connected status, we no longer invoke the write callback as well unless we actually wrote data too. - + o If the kernel tells us that there are a negative number of bytes to read from a socket, do not believe it. Fixes bug 2841177; found by Alexander Pronchenkov. Changes in 2.0.2-alpha: o Add a new flag to bufferevents to make all callbacks automatically deferred. diff --git a/buffer.c b/buffer.c index 0cd6df50..370823e2 100644 --- a/buffer.c +++ b/buffer.c @@ -1607,9 +1607,9 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch) #if defined(FIONREAD) #ifdef WIN32 - if (ioctlsocket(fd, FIONREAD, &lng) == -1 || (n=lng) == 0) { + if (ioctlsocket(fd, FIONREAD, &lng) == -1 || (n=lng) <= 0) { #else - if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) { + if (ioctl(fd, FIONREAD, &n) == -1 || n <= 0) { #endif n = EVBUFFER_MAX_READ; } else if (n > EVBUFFER_MAX_READ && n > howmuch) {