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) {
case AF_UNSPEC:
if (address != null) {
throw new HAProxyProtocolException("unable to validate an AF_UNSPEC address: " + address); throw new HAProxyProtocolException("unable to validate an AF_UNSPEC address: " + address);
} }
return;
if (addrFamily == AddressFamily.AF_UNIX) { case AF_UNIX:
return; return;
} }
boolean isValid = true; if (address == null) {
throw new NullPointerException("address");
if (addrFamily == AddressFamily.AF_IPv4) {
isValid = NetUtil.isValidIpV4Address(address);
} else if (addrFamily == AddressFamily.AF_IPv6) {
isValid = NetUtil.isValidIpV6Address(address);
} }
if (!isValid) { switch (addrFamily) {
throw new HAProxyProtocolException("invalid " + addrFamily + " address: " + address); case AF_IPv4:
if (!NetUtil.isValidIpV4Address(address)) {
throw new HAProxyProtocolException("invalid IPv4 address: " + address);
}
break;
case AF_IPv6:
if (!NetUtil.isValidIpV6Address(address)) {
throw new HAProxyProtocolException("invalid IPv6 address: " + address);
}
break;
default:
throw new Error();
} }
} }