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.
This commit is contained in:
Tomash Brechko 2011-03-23 12:05:33 +03:00 committed by Nick Mathewson
parent c621359122
commit 272823f8b0

15
http.c
View File

@ -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",