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 <adrian.sutton@consensys.net>
pull/2/head
Adrian Sutton 6 years ago committed by GitHub
parent 3e3b7c2b92
commit 945f979357
  1. 2
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java
  2. 11
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.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);

@ -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 {

Loading…
Cancel
Save