Skip to content

Commit f8adf80

Browse files
author
Shigeki Ohtsu
committed
tls_wrap: fix error cb when fatal TLS Alert recvd
SSL_read() returns 0 when fatal TLS Alert is received. Fix to invoke ssl error callback in this case.
1 parent 56129de commit f8adf80

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/tls_wrap.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
352352
Local<Value> TLSWrap::GetSSLError(int status, int* err, const char** msg) {
353353
EscapableHandleScope scope(env()->isolate());
354354

355+
// ssl_ is already destroyed in reading EOF by close notify alert.
356+
if (ssl_ == nullptr)
357+
return Local<Value>();
358+
355359
*err = SSL_get_error(ssl_, status);
356360
switch (*err) {
357361
case SSL_ERROR_NONE:
@@ -432,7 +436,10 @@ void TLSWrap::ClearOut() {
432436
OnRead(UV_EOF, nullptr);
433437
}
434438

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

0 commit comments

Comments
 (0)