From 945f97935720d5d619f1adc56f80692ab49c736a Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 29 May 2019 07:03:39 +1000 Subject: [PATCH] Treat RLPException when processing a message as an indication that the message is invalid and disconnect the client for breach of protocol. (#1491) Signed-off-by: Adrian Sutton --- .../pantheon/ethereum/p2p/network/netty/DeFramer.java | 2 +- .../ethereum/p2p/network/netty/DeFramerTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java index 2a0499fdad..f4761c1bff 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java @@ -190,7 +190,7 @@ final class DeFramer extends ByteToMessageDecoder { throwable instanceof DecoderException && throwable.getCause() != null ? throwable.getCause() : throwable; - if (cause instanceof FramingException) { + if (cause instanceof FramingException || cause instanceof RLPException) { LOG.debug("Invalid incoming message", throwable); if (connectFuture.isDone() && !connectFuture.isCompletedExceptionally()) { connectFuture.get().disconnect(DisconnectReason.BREACH_OF_PROTOCOL); diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.java index c95e663d49..2d4df5fa3b 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.java @@ -43,6 +43,7 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.Discon import tech.pegasys.pantheon.ethereum.p2p.wire.messages.HelloMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.PingMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.WireMessageCodes; +import tech.pegasys.pantheon.ethereum.rlp.RLPException; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -123,6 +124,16 @@ public class DeFramerTest { verify(peerConnection).disconnect(DisconnectReason.BREACH_OF_PROTOCOL); } + @Test + public void exceptionCaught_shouldDisconnectForBreachOfProtocolWhenRlpExceptionThrown() + throws Exception { + connectFuture.complete(peerConnection); + + deFramer.exceptionCaught(ctx, new DecoderException(new RLPException("Test"))); + + verify(peerConnection).disconnect(DisconnectReason.BREACH_OF_PROTOCOL); + } + @Test public void exceptionCaught_shouldHandleFramingExceptionWhenFutureCompletedExceptionally() throws Exception {