Fix possible NPE in ReferenceCountedOpenSslEngine.rejectRemoteInitiatedRenegotiation()

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 [#7353].
This commit is contained in:
Norman Maurer 2017-11-01 08:09:04 +01:00
parent b5849f5e08
commit 26417cf2ad

View File

@ -1094,7 +1094,10 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
}
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();