]> granicus.if.org Git - libevent/commit
Fix crashing http server when callback do not reply in place
authorAzat Khuzhin <a3at.mail@gmail.com>
Sun, 22 Oct 2017 21:13:37 +0000 (00:13 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Sun, 29 Oct 2017 17:30:42 +0000 (20:30 +0300)
commit5ff8eb26371c4dc56f384b2de35bea2d87814779
treefe5a628b2d1ab01edab31d25f7cd8a5cdc105d10
parentda3f2ba22adcabaf7355a90d537b4928d0c168d2
Fix crashing http server when callback do not reply in place

General http callback looks like:
  static void http_cb(struct evhttp_request *req, void *arg)
  {
    evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
  }

And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
  static void http_cb(struct evhttp_request *req, void *arg)
  {
    return;
  }

This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
  [err] ../http.c: illegal connection state 7

Because it thinks that read for now is not possible, since there were no
write.

Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.

Reported-by: Cory Fields <cory@coryfields.com>
http.c
test/regress_http.c