Skip to content

Commit

Permalink
tls_wrap: fix error cb when fatal TLS Alert recvd
Browse files Browse the repository at this point in the history
SSL_read() returns 0 when fatal TLS Alert is received.
Fix to invoke ssl error callback in this case.
  • Loading branch information
Shigeki Ohtsu committed May 9, 2015
1 parent 56129de commit f8adf80
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
Local<Value> TLSWrap::GetSSLError(int status, int* err, const char** msg) {
EscapableHandleScope scope(env()->isolate());

// ssl_ is already destroyed in reading EOF by close notify alert.
if (ssl_ == nullptr)
return Local<Value>();

*err = SSL_get_error(ssl_, status);
switch (*err) {
case SSL_ERROR_NONE:
Expand Down Expand Up @@ -432,7 +436,10 @@ void TLSWrap::ClearOut() {
OnRead(UV_EOF, nullptr);
}

if (read == -1) {
// We need to check whether an error occurred or the connection was
// shutdown cleanly (SSL_ERROR_ZERO_RETURN) even when read == 0.
// See iojs#1642 and SSL_read(3SSL) for details.
if (read <= 0) {
int err;
Local<Value> arg = GetSSLError(read, &err, nullptr);

Expand Down

0 comments on commit f8adf80

Please sign in to comment.