Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
tls: fix assertion when ssl is destroyed at read
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
indutny committed Aug 21, 2013
1 parent e04c8a8 commit af6a233
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,14 @@ CryptoStream.prototype._read = function read(size) {

// Get NPN and Server name when ready
this.pair.maybeInitFinished();
} while (read > 0 && !this._buffer.isFull && bytesRead < size);

// `maybeInitFinished()` can emit the 'secure' event which
// in turn destroys the connection in case of authentication
// failure and sets `this.pair.ssl` to `null`.
} while (read > 0 &&
!this._buffer.isFull &&
bytesRead < size &&
this.pair.ssl !== null);

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

0 comments on commit af6a233

Please sign in to comment.