diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-12-29 19:50:03 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-12-29 19:50:03 -0500 |
commit | 2e8eeea3e86b1f577e34ef2bc4f7099d848ae787 (patch) | |
tree | 045ebf8a1765c21cc6240c400136b0f1be27c422 /bufferevent_filter.c | |
parent | 0b151a9fa1365ad9f6f2e58fcfcfb36840707403 (diff) | |
download | libevent-2e8eeea3e86b1f577e34ef2bc4f7099d848ae787.tar.gz |
Fix crash bugs when a bufferevent's eventcb is not set.
In many places throughout the code, we called _bufferevent_run_eventcb
without checking whether the eventcb was actually set. This would
work fine when the bufferevent's callbacks were deferred, but
otherwise the code would segfault. Strangely, we always remembered to
check before calling the _bufferevent_run_{read,write}cb functions.
To prevent similar errors in the future, all of
_buferevent_run_{read,write,event}cb now check to make sure the
callback is actually set before invoking or deferring the callback.
This patch also removes the now-redundant checks for {read,write}cb.
Diffstat (limited to 'bufferevent_filter.c')
-rw-r--r-- | bufferevent_filter.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/bufferevent_filter.c b/bufferevent_filter.c index dedca445..b7e1bc6a 100644 --- a/bufferevent_filter.c +++ b/bufferevent_filter.c @@ -329,7 +329,7 @@ be_filter_process_output(struct bufferevent_filtered *bevf, /* Or if we have filled the underlying output buffer. */ !be_underlying_writebuf_full(bevf,state)); - if (processed && bufev->writecb && + if (processed && evbuffer_get_length(bufev->output) <= bufev->wm_write.low) { /* call the write callback.*/ _bufferevent_run_writecb(bufev); @@ -394,8 +394,7 @@ be_filter_readcb(struct bufferevent *underlying, void *_me) * other places that can call process-input, and they should * force readcb calls as needed. */ if (processed_any && - evbuffer_get_length(bufev->input) >= bufev->wm_read.low && - bufev->readcb != NULL) + evbuffer_get_length(bufev->input) >= bufev->wm_read.low) _bufferevent_run_readcb(bufev); _bufferevent_decref_and_unlock(bufev); @@ -424,8 +423,7 @@ be_filter_eventcb(struct bufferevent *underlying, short what, void *_me) _bufferevent_incref_and_lock(bev); /* All we can really to is tell our own eventcb. */ - if (bev->errorcb) - _bufferevent_run_eventcb(bev, what); + _bufferevent_run_eventcb(bev, what); _bufferevent_decref_and_unlock(bev); } |