From 81765181c62bc02a5caa3dc25c32f30cd99ab659 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 11 Sep 2009 18:55:06 +0000 Subject: [PATCH] Backport: do not believe negative result from FIONREAD. svn:r1429 --- ChangeLog | 3 +++ buffer.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2435c1f1..68c95f5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Changes in 1.4.13-stable: + 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 1.4.12-stable: o Try to contain degree of failure when running on a win32 version so heavily firewalled that we can't fake a socketpair. o Fix an obscure timing-dependent, allocator-dependent crash in the evdns code. diff --git a/buffer.c b/buffer.c index 9cb0f0ce..6d1758d5 100644 --- a/buffer.c +++ b/buffer.c @@ -357,9 +357,9 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch) #if defined(FIONREAD) #ifdef WIN32 long lng = n; - 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) {