Fix an incorrect use of ByteBuf.array() in Socks5CmdRequestDecoder

Motivation:

Socks5CmdRequestDecoder uses ByteBuf.array() naively assuming that the
array's base offset is always 0, which is not the case.

Modification:

- Allocate a new byte array and copy the content there instead

Result:

Another bug fixed
This commit is contained in:
Trustin Lee 2014-09-16 19:11:40 +09:00
parent 9839990fff
commit 0b935b85ce

View File

@ -75,7 +75,18 @@ public class Socks5CmdRequestDecoder extends ReplayingDecoder<State> {
break;
}
case IPv6: {
host = Socks5CommonUtils.ipv6toStr(byteBuf.readBytes(16).array());
if (actualReadableBytes() < 16) {
// Let it replay.
byteBuf.readBytes(16);
// Should never reach here.
throw new Error();
}
byte[] byteArray = new byte[16];
byteBuf.readBytes(byteArray);
host = Socks5CommonUtils.ipv6toStr(byteArray);
port = byteBuf.readUnsignedShort();
msg = new Socks5CmdRequest(cmdType, addressType, host, port);
break;