Skip to content

Commit

Permalink
Fix possible NPE in ReferenceCountedOpenSslEngine.rejectRemoteInitiat…
Browse files Browse the repository at this point in the history
…edRenegotiation()

Motivation:

ReferenceCountedOpenSslEngine.rejectRemoteInitiatedRenegotiation() is called in a finally block to ensure we always check for renegotiation. The problem here is that sometimes we will already shutdown the engine before we call the method which will lead to an NPE in this case as the ssl pointer was already destroyed.

Modifications:

Check that the engine is not destroyed yet before calling SSL.getHandshakeCount(...)

Result:

Fixes [netty#7353].
  • Loading branch information
normanmaurer authored and andsel committed Nov 15, 2017
1 parent 2de8356 commit 64c4af9
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,10 @@ private void closeAll() throws SSLException {
}

private void rejectRemoteInitiatedRenegotiation() throws SSLHandshakeException {
if (rejectRemoteInitiatedRenegotiation && SSL.getHandshakeCount(ssl) > 1) {
// As rejectRemoteInitiatedRenegotiation() is called in a finally block we also need to check if we shutdown
// the engine before as otherwise SSL.getHandshakeCount(ssl) will throw an NPE if the passed in ssl is 0.
// See https://github.com/netty/netty/issues/7353
if (rejectRemoteInitiatedRenegotiation && !isDestroyed() && SSL.getHandshakeCount(ssl) > 1) {
// TODO: In future versions me may also want to send a fatal_alert to the client and so notify it
// that the renegotiation failed.
shutdown();
Expand Down

0 comments on commit 64c4af9

Please sign in to comment.