Skip to content

Commit af6a233

Browse files
committed
tls: fix assertion when ssl is destroyed at read
`maybeInitFinished()` can emit the 'secure' event which in turn destroys the connection in case of authentication failure and sets `this.pair.ssl` to `null`. If such condition appeared after non-empty read - loop will continue and `clearOut` will be called on `null` object instead of `crypto::Connection` instance. Resulting in the following assertion: ERROR: Error: Hostname/IP doesn't match certificate's altnames Assertion failed: handle->InternalFieldCount() > 0 fix #5756
1 parent e04c8a8 commit af6a233

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/tls.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,14 @@ CryptoStream.prototype._read = function read(size) {
461461

462462
// Get NPN and Server name when ready
463463
this.pair.maybeInitFinished();
464-
} while (read > 0 && !this._buffer.isFull && bytesRead < size);
464+
465+
// `maybeInitFinished()` can emit the 'secure' event which
466+
// in turn destroys the connection in case of authentication
467+
// failure and sets `this.pair.ssl` to `null`.
468+
} while (read > 0 &&
469+
!this._buffer.isFull &&
470+
bytesRead < size &&
471+
this.pair.ssl !== null);
465472

466473
// Create new buffer if previous was filled up
467474
var pool = this._buffer.pool;

0 commit comments

Comments
 (0)