Fix test failures due to incorrect validation

This commit is contained in:
Trustin Lee 2014-06-21 17:11:08 +09:00
parent 365b3f5e11
commit 3ad96d647c

View File

@ -334,32 +334,37 @@ public final class HAProxyMessage {
* @throws HAProxyProtocolException if the address is invalid * @throws HAProxyProtocolException if the address is invalid
*/ */
private static void checkAddress(String address, AddressFamily addrFamily) { private static void checkAddress(String address, AddressFamily addrFamily) {
if (address == null) {
throw new NullPointerException("address");
}
if (addrFamily == null) { if (addrFamily == null) {
throw new NullPointerException("addrFamily"); throw new NullPointerException("addrFamily");
} }
if (addrFamily == AddressFamily.AF_UNSPEC) { switch (addrFamily) {
throw new HAProxyProtocolException("unable to validate an AF_UNSPEC address: " + address); case AF_UNSPEC:
if (address != null) {
throw new HAProxyProtocolException("unable to validate an AF_UNSPEC address: " + address);
}
return;
case AF_UNIX:
return;
} }
if (addrFamily == AddressFamily.AF_UNIX) { if (address == null) {
return; throw new NullPointerException("address");
} }
boolean isValid = true; switch (addrFamily) {
case AF_IPv4:
if (addrFamily == AddressFamily.AF_IPv4) { if (!NetUtil.isValidIpV4Address(address)) {
isValid = NetUtil.isValidIpV4Address(address); throw new HAProxyProtocolException("invalid IPv4 address: " + address);
} else if (addrFamily == AddressFamily.AF_IPv6) { }
isValid = NetUtil.isValidIpV6Address(address); break;
} case AF_IPv6:
if (!NetUtil.isValidIpV6Address(address)) {
if (!isValid) { throw new HAProxyProtocolException("invalid IPv6 address: " + address);
throw new HAProxyProtocolException("invalid " + addrFamily + " address: " + address); }
break;
default:
throw new Error();
} }
} }