]> granicus.if.org Git - libevent/commitdiff
Don't call BIO_number_{read|written} on NULL BIOs.
authorAdam Langley <agl@google.com>
Thu, 13 Oct 2016 00:49:17 +0000 (17:49 -0700)
committerAzat Khuzhin <a3at.mail@gmail.com>
Sat, 15 Oct 2016 23:09:43 +0000 (02:09 +0300)
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)
bufferevent_openssl.c

index 017bfce62308a24794d215bf1c07392f1e3a2a6d..4e93ad5310c8fcaf1fcef1e86ebccad70c26a154 100644 (file)
@@ -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