Skip to content

Commit

Permalink
SslHandler.wrap(...) must ensure it not loose the original exception …
Browse files Browse the repository at this point in the history
…when finishWrap(...) fails (netty#9974)

Motivation:

When SslHandler.finishWrap throws an exception, ensure that the promise and buf is not reused to avoid throwing IllegalArgumentException or IllegalReferenceCountException which causes the original exception to be lost.

Modification:

The change ensures that the values for the promise and bytebuf are nulled before calling finishWrap so that it will not be called again with the same arguments.

Result:

Fixes netty#9971 .

Co-authored-by: Norman Maurer <[email protected]>

Co-authored-by: Antony T Curtis <[email protected]>
  • Loading branch information
normanmaurer and atcurtis authored Jan 29, 2020
1 parent fb3ced2 commit 663fbaa
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions handler/src/main/java/io/netty/handler/ssl/SslHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,25 @@ private void wrap(ChannelHandlerContext ctx, boolean inUnwrap) throws SSLExcepti
case NOT_HANDSHAKING:
setHandshakeSuccessIfStillHandshaking();
// deliberate fall-through
case NEED_WRAP:
finishWrap(ctx, out, promise, inUnwrap, false);
case NEED_WRAP: {
ChannelPromise p = promise;

// Null out the promise so it is not reused in the finally block in the cause of
// finishWrap(...) throwing.
promise = null;
out = null;
final ByteBuf b;

if (out.isReadable()) {
// There is something in the out buffer. Ensure we null it out so it is not re-used.
b = out;
out = null;
} else {
// If out is not readable we can re-use it and so save an extra allocation
b = null;
}
finishWrap(ctx, b, p, inUnwrap, false);
break;
}
case NEED_UNWRAP:
needUnwrap = true;
return;
Expand Down

0 comments on commit 663fbaa

Please sign in to comment.