]> granicus.if.org Git - libevent/commitdiff
Reset outgoing connection when read data in idle state.
authorTomash Brechko <tomash.brechko@gmail.com>
Wed, 23 Mar 2011 09:05:33 +0000 (12:05 +0300)
committerNick Mathewson <nickm@torproject.org>
Mon, 4 Apr 2011 18:41:45 +0000 (14:41 -0400)
Imagine server side is buggy and miscalculates Content-Length: in the
reply.  Data arriving in idle state shouldn't make us crash, instead we
can just reset the connection.

http.c

diff --git a/http.c b/http.c
index 3a24df2f1e7be515f7aee6039b8cae0c7f397738..1429462edcebfe236630058a16098c89d0836a93 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1021,9 +1021,22 @@ evhttp_read_cb(struct bufferevent *bufev, void *arg)
        case EVCON_READING_TRAILER:
                evhttp_read_trailer(evcon, req);
                break;
+       case EVCON_IDLE:
+               {
+                       struct evbuffer *input;
+                       size_t total_len;
+
+                       input = bufferevent_get_input(evcon->bufev);
+                       total_len = evbuffer_get_length(input);
+                       event_debug(("%s: read %d bytes in EVCON_IDLE state,"
+                                    " resetting connection",
+                                       __func__, (int)total_len));
+
+                       evhttp_connection_reset(evcon);
+               }
+               break;
        case EVCON_DISCONNECTED:
        case EVCON_CONNECTING:
-       case EVCON_IDLE:
        case EVCON_WRITING:
        default:
                event_errx(1, "%s: illegal connection state %d",