Fix a bug in SslHandler where a ClassCastException is raised when non-ByteBuf message is passed

- Fixes #1828
This commit is contained in:
Trustin Lee 2013-12-16 16:30:24 +09:00
parent 6ddfab3c9c
commit 02a79c51e5
2 changed files with 25 additions and 1 deletions

View File

@ -437,6 +437,12 @@ public class SslHandler extends ByteToMessageDecoder {
out = ctx.alloc().buffer(maxPacketBufferSize); out = ctx.alloc().buffer(maxPacketBufferSize);
} }
if (!(pending.msg() instanceof ByteBuf)) {
ctx.write(pending.msg(), (ChannelPromise) pending.recycleAndGet());
pendingUnencryptedWrites.remove();
continue;
}
ByteBuf buf = (ByteBuf) pending.msg(); ByteBuf buf = (ByteBuf) pending.msg();
SSLEngineResult result = wrap(engine, buf, out); SSLEngineResult result = wrap(engine, buf, out);

View File

@ -38,7 +38,7 @@ public class SslHandlerTest {
EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(engine)); EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(engine));
// Push the first part of a 5-byte handshake message. // Push the first part of a 5-byte handshake message.
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 22, 3, 1, 0, 5 })); ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{22, 3, 1, 0, 5}));
// Should decode nothing yet. // Should decode nothing yet.
assertThat(ch.readInbound(), is(nullValue())); assertThat(ch.readInbound(), is(nullValue()));
@ -52,4 +52,22 @@ public class SslHandlerTest {
assertThat(e.getCause(), is(instanceOf(SSLProtocolException.class))); assertThat(e.getCause(), is(instanceOf(SSLProtocolException.class)));
} }
} }
@Test
public void testNonByteBufPassthrough() throws Exception {
SSLEngine engine = SSLContext.getDefault().createSSLEngine();
engine.setUseClientMode(false);
EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(engine));
Object msg1 = new Object();
ch.writeOutbound(msg1);
assertThat(ch.readOutbound(), is(sameInstance(msg1)));
Object msg2 = new Object();
ch.writeInbound(msg2);
assertThat(ch.readInbound(), is(sameInstance(msg2)));
ch.finish();
}
} }