Skip to content

Commit 527cecc

Browse files
yfeldblumfacebook-github-bot
authored andcommitted
avoid crashing when OpenSSL error-string functions return nullptr
Summary: Closes: facebook/folly#1388. If `ERR_func_error_string` or `ERR_reason_error_string` were to return `nullptr` while `VLOG` were enabled, the program might crash. Avoid this scenario by emitting a default string rather than `nullptr` to `VLOG`. Reviewed By: Orvid Differential Revision: D62074115 fbshipit-source-id: 3283f576a7d5884a6da84ffee7458575eaf73afd
1 parent 87a2168 commit 527cecc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

third-party/folly/src/folly/io/async/AsyncSSLSocket.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ SpinLock dummyCtxLock;
6161
// stack, otherwise it is allocated on heap
6262
const size_t MAX_STACK_BUF_SIZE = 2048;
6363

64+
char const* str_or(char const* const str, char const* const def = "(unknown)") {
65+
return str ? str : def;
66+
}
67+
6468
void setup_SSL_CTX(SSL_CTX* ctx) {
6569
#ifdef SSL_MODE_RELEASE_BUFFERS
6670
SSL_CTX_set_mode(
@@ -1183,8 +1187,8 @@ bool AsyncSSLSocket::willBlock(
11831187
<< "errno: " << errno << ", " << "ret: " << ret << ", "
11841188
<< "read: " << BIO_number_read(SSL_get_rbio(ssl_.get())) << ", "
11851189
<< "written: " << BIO_number_written(SSL_get_wbio(ssl_.get()))
1186-
<< ", " << "func: " << ERR_func_error_string(lastError) << ", "
1187-
<< "reason: " << ERR_reason_error_string(lastError);
1190+
<< ", " << "func: " << str_or(ERR_func_error_string(lastError))
1191+
<< ", " << "reason: " << str_or(ERR_reason_error_string(lastError));
11881192
return false;
11891193
}
11901194
}
@@ -1576,8 +1580,8 @@ AsyncSocket::ReadResult AsyncSSLSocket::performReadSingle(
15761580
<< "events=" << std::hex << eventFlags_
15771581
<< "): " << "bytes: " << bytes << ", " << "error: " << error
15781582
<< ", " << "errno: " << local_errno << ", "
1579-
<< "func: " << ERR_func_error_string(errError) << ", "
1580-
<< "reason: " << ERR_reason_error_string(errError);
1583+
<< "func: " << str_or(ERR_func_error_string(errError)) << ", "
1584+
<< "reason: " << str_or(ERR_reason_error_string(errError));
15811585
return ReadResult(
15821586
READ_ERROR,
15831587
std::make_unique<SSLException>(error, errError, bytes, local_errno));
@@ -1692,8 +1696,8 @@ AsyncSocket::WriteResult AsyncSSLSocket::interpretSSLError(int rc, int error) {
16921696
VLOG(3) << "ERROR: AsyncSSLSocket(fd=" << fd_ << ", state=" << int(state_)
16931697
<< ", sslState=" << sslState_ << ", events=" << eventFlags_
16941698
<< "): " << "SSL error: " << error << ", errno: " << errno
1695-
<< ", func: " << ERR_func_error_string(errError)
1696-
<< ", reason: " << ERR_reason_error_string(errError);
1699+
<< ", func: " << str_or(ERR_func_error_string(errError))
1700+
<< ", reason: " << str_or(ERR_reason_error_string(errError));
16971701
return WriteResult(
16981702
WRITE_ERROR,
16991703
std::make_unique<SSLException>(error, errError, rc, errno));

0 commit comments

Comments
 (0)