From: Kyle Nekritz Date: Mon, 7 Dec 2015 19:04:13 +0000 (-0800) Subject: Fix segfaults in AsyncSSLSocket when used in unencrypted mode. X-Git-Tag: deprecate-dynamic-initializer~205 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=df9360f488069103e72267f32d119ec34cd8c12b;p=folly.git Fix segfaults in AsyncSSLSocket when used in unencrypted mode. Reviewed By: djwatson Differential Revision: D2720027 fb-gh-sync-id: 1d56aabedeaf65a5d48e152eaee5c81695be7620 --- diff --git a/folly/io/async/AsyncSSLSocket.cpp b/folly/io/async/AsyncSSLSocket.cpp index 8874235d..166a4039 100644 --- a/folly/io/async/AsyncSSLSocket.cpp +++ b/folly/io/async/AsyncSSLSocket.cpp @@ -412,6 +412,9 @@ std::string AsyncSSLSocket::getApplicationProtocol() noexcept { } bool AsyncSSLSocket::isEorTrackingEnabled() const { + if (ssl_ == nullptr) { + return false; + } const BIO *wb = SSL_get_wbio(ssl_); return wb && wb->method == &eorAwareBioMethod; } @@ -1094,7 +1097,8 @@ AsyncSSLSocket::handleConnect() noexcept { void AsyncSSLSocket::setReadCB(ReadCallback *callback) { #ifdef SSL_MODE_MOVE_BUFFER_OWNERSHIP // turn on the buffer movable in openssl - if (!isBufferMovable_ && callback != nullptr && callback->isBufferMovable()) { + if (ssl_ != nullptr && !isBufferMovable_ && + callback != nullptr && callback->isBufferMovable()) { SSL_set_mode(ssl_, SSL_get_mode(ssl_) | SSL_MODE_MOVE_BUFFER_OWNERSHIP); isBufferMovable_ = true; }