From 272823f8b0fb3c5f752ea5ff79b9b223b4d1b453 Mon Sep 17 00:00:00 2001 From: Tomash Brechko Date: Wed, 23 Mar 2011 12:05:33 +0300 Subject: [PATCH] Reset outgoing connection when read data in idle state. 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/http.c b/http.c index 3a24df2f..1429462e 100644 --- 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", -- 2.40.0