From: Adam Langley Date: Thu, 13 Oct 2016 00:49:17 +0000 (-0700) Subject: Don't call BIO_number_{read|written} on NULL BIOs. X-Git-Tag: release-2.1.7-rc~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6702da1a8ca6043aea662e191289869070e4f10d;p=libevent Don't call BIO_number_{read|written} on NULL BIOs. OpenSSL doesn't document the behaviour of these functions when given a NULL BIO, and it happens to return zero at the moment. But don't depend on that. Closes: #406 (cherry-picked) --- diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c index 017bfce6..4e93ad53 100644 --- a/bufferevent_openssl.c +++ b/bufferevent_openssl.c @@ -542,10 +542,10 @@ conn_closed(struct bufferevent_openssl *bev_ssl, int when, int errcode, int ret) static void init_bio_counts(struct bufferevent_openssl *bev_ssl) { - bev_ssl->counts.n_written = - BIO_number_written(SSL_get_wbio(bev_ssl->ssl)); - bev_ssl->counts.n_read = - BIO_number_read(SSL_get_rbio(bev_ssl->ssl)); + BIO *wbio = SSL_get_wbio(bev_ssl->ssl); + bev_ssl->counts.n_written = wbio ? BIO_number_written(wbio) : 0; + BIO *rbio = SSL_get_rbio(bev_ssl->ssl); + bev_ssl->counts.n_read = rbio ? BIO_number_read(rbio) : 0; } static inline void