From be133b8d348111ab383934e836b763df5ceb98f7 Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Fri, 22 Jul 2022 19:43:23 +1000 Subject: [PATCH] fix 1 byte long disconnect reason (#4150) Signed-off-by: Stefan --- .../ethereum/p2p/rlpx/connections/netty/DeFramer.java | 2 +- .../p2p/rlpx/wire/messages/DisconnectMessage.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/DeFramer.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/DeFramer.java index 597784f913..44d325d732 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/DeFramer.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/DeFramer.java @@ -205,7 +205,7 @@ final class DeFramer extends ByteToMessageDecoder { if (remoteAddress == null) { return Optional.empty(); } - int port = peerInfo.getPort(); + final int port = peerInfo.getPort(); return Optional.of( DefaultPeer.fromEnodeURL( EnodeURLImpl.builder() diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/wire/messages/DisconnectMessage.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/wire/messages/DisconnectMessage.java index 71ffe01894..3871939ea3 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/wire/messages/DisconnectMessage.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/wire/messages/DisconnectMessage.java @@ -80,9 +80,14 @@ public final class DisconnectMessage extends AbstractMessageData { } public static Data readFrom(final RLPInput in) { - in.enterList(); - Bytes reasonData = in.readBytes(); - in.leaveList(); + Bytes reasonData = Bytes.EMPTY; + if (in.nextIsList()) { + in.enterList(); + reasonData = in.readBytes(); + in.leaveList(); + } else if (in.nextSize() == 1) { + reasonData = in.readBytes(); + } // Disconnect reason should be at most 1 byte, otherwise, just return UNKNOWN final DisconnectReason reason =