DefaultSocks5CommandRequest incorrectly rejects SOCKS5 commands with dstPort=0

Motivation:

According to SOCKS 5 spec, dstPort = 0 is a valid value in case of UDP ASSOCIATE.

Modifications:

- Allow 0 as port.
- Add unit tests.

Result:

Fixes [#7156].
This commit is contained in:
Norman Maurer 2017-08-28 10:58:34 +02:00
parent d9d0e633dc
commit f5bea11ee4
2 changed files with 8 additions and 3 deletions

View File

@ -59,8 +59,8 @@ public final class DefaultSocks5CommandRequest extends AbstractSocks5Message imp
}
}
if (dstPort <= 0 || dstPort >= 65536) {
throw new IllegalArgumentException("dstPort: " + dstPort + " (expected: 1~65535)");
if (dstPort < 0 || dstPort > 65535) {
throw new IllegalArgumentException("dstPort: " + dstPort + " (expected: 0~65535)");
}
this.type = type;

View File

@ -76,7 +76,7 @@ public class DefaultSocks5CommandRequestTest {
public void testValidPortRange() {
try {
new DefaultSocks5CommandRequest(Socks5CommandType.BIND, Socks5AddressType.DOMAIN,
"παράδειγμα.δοκιμήπαράδει", 0);
"παράδειγμα.δοκιμήπαράδει", -1);
} catch (Exception e) {
assertTrue(e instanceof IllegalArgumentException);
}
@ -87,5 +87,10 @@ public class DefaultSocks5CommandRequestTest {
} catch (Exception e) {
assertTrue(e instanceof IllegalArgumentException);
}
new DefaultSocks5CommandRequest(Socks5CommandType.BIND, Socks5AddressType.DOMAIN,
"παράδειγμα.δοκιμήπαράδει", 0);
new DefaultSocks5CommandRequest(Socks5CommandType.BIND, Socks5AddressType.DOMAIN,
"παράδειγμα.δοκιμήπαράδει", 65535);
}
}