From 5bb677e7c2a37d40c7dac6bb770df5915cbda90d Mon Sep 17 00:00:00 2001 From: Dominik Obermaier Date: Thu, 29 Sep 2016 15:30:18 +0200 Subject: [PATCH] This PR fixes an issue with the PROXY protocol where the reader index of a consumed byte array was not set correctly. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Motivation: When using the AF_UNIX PROXY protocol, the reader index was not set correctly after consuming the message bytes of the original header ByteBuf. This caused no immediate harm because after the codepath there is no consumer of the ByteBuf in the current implementation. It’s a bug nevertheless, because consumers of the ByteBuf for extensions (like TLVs, which are allowed by the PROXY protocol spec) would consume a ByteBuf that has a wrong readerIndex when using AF_UNIX instead of e.g. IPv4 (which has correct behaviour) Modifications: Increase the reader index of the ByteBuf after it was read Result: Correct and consistent behaviour of the AF_UNIX codepath --- .../java/io/netty/handler/codec/haproxy/HAProxyMessage.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java b/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java index 5c3f804d3d..fb2b4d4cd5 100644 --- a/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java +++ b/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java @@ -182,6 +182,9 @@ public final class HAProxyMessage { addressLen = addressEnd - startIdx; } dstAddress = header.toString(startIdx, addressLen, CharsetUtil.US_ASCII); + // AF_UNIX defines that exactly 108 bytes are reserved for the address. The previous methods + // did not increase the reader index although we already consumed the information. + header.readerIndex(startIdx + 108); } else { if (addressFamily == AddressFamily.AF_IPv4) { // IPv4 requires 12 bytes for address information