Skip to content

Commit

Permalink
Fix an incorrect use of ByteBuf.array() in Socks5CmdRequestDecoder
Browse files Browse the repository at this point in the history
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
  • Loading branch information
trustin committed Oct 14, 2014
1 parent 9839990 commit 0b935b8
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> o
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;
Expand Down

0 comments on commit 0b935b8

Please sign in to comment.