From 1b6e47ab2be03cb0d1cafcdf3862ed6591636e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Tue, 18 Sep 2018 23:20:28 +0200 Subject: [PATCH] Fix incorrectly encoded empty SOCKS5 address (#8292) Motivation: If you encode a SOCKS5 message like new DefaultSocks5CommandResponse(FAILURE, DOMAIN, "", 0) you correctly get a result of 05010003000000. But if the bndAddr is null, for example like new DefaultSocks5CommandResponse(FAILURE, DOMAIN) the encoded result is 0501000301000000 which means the domain name has a length of one and consists of a 0-byte. Modification: With this commit it is also correctly encoded as a string of 0 length. Result: Correctly encode empty SOCKS5 address --- .../io/netty/handler/codec/socksx/v5/Socks5AddressEncoder.java | 1 - .../codec/socksx/v5/DefaultSocks5CommandResponseTest.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5AddressEncoder.java b/codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5AddressEncoder.java index fcd29cf3f3..390622caba 100644 --- a/codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5AddressEncoder.java +++ b/codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5AddressEncoder.java @@ -44,7 +44,6 @@ public interface Socks5AddressEncoder { out.writeByte(addrValue.length()); out.writeCharSequence(addrValue, CharsetUtil.US_ASCII); } else { - out.writeByte(1); out.writeByte(0); } } else if (typeVal == Socks5AddressType.IPv6.byteValue()) { diff --git a/codec-socks/src/test/java/io/netty/handler/codec/socksx/v5/DefaultSocks5CommandResponseTest.java b/codec-socks/src/test/java/io/netty/handler/codec/socksx/v5/DefaultSocks5CommandResponseTest.java index 36fea75027..9da123602e 100755 --- a/codec-socks/src/test/java/io/netty/handler/codec/socksx/v5/DefaultSocks5CommandResponseTest.java +++ b/codec-socks/src/test/java/io/netty/handler/codec/socksx/v5/DefaultSocks5CommandResponseTest.java @@ -51,8 +51,7 @@ public class DefaultSocks5CommandResponseTest { 0x00, // success reply 0x00, // reserved 0x03, // address type domain - 0x01, // length of domain - 0x00, // domain value + 0x00, // length of domain 0x00, // port value 0x00 };