Skip to content

Commit

Permalink
Fix test failures due to incorrect validation
Browse files Browse the repository at this point in the history
  • Loading branch information
trustin committed Jun 21, 2014
1 parent 365b3f5 commit 3ad96d6
Showing 1 changed file with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,32 +334,37 @@ private static int portStringToInt(String value) {
* @throws HAProxyProtocolException if the address is invalid
*/
private static void checkAddress(String address, AddressFamily addrFamily) {
if (address == null) {
throw new NullPointerException("address");
}

if (addrFamily == null) {
throw new NullPointerException("addrFamily");
}

if (addrFamily == AddressFamily.AF_UNSPEC) {
throw new HAProxyProtocolException("unable to validate an AF_UNSPEC address: " + address);
}

if (addrFamily == AddressFamily.AF_UNIX) {
return;
switch (addrFamily) {
case AF_UNSPEC:
if (address != null) {
throw new HAProxyProtocolException("unable to validate an AF_UNSPEC address: " + address);
}
return;
case AF_UNIX:
return;
}

boolean isValid = true;

if (addrFamily == AddressFamily.AF_IPv4) {
isValid = NetUtil.isValidIpV4Address(address);
} else if (addrFamily == AddressFamily.AF_IPv6) {
isValid = NetUtil.isValidIpV6Address(address);
if (address == null) {
throw new NullPointerException("address");
}

if (!isValid) {
throw new HAProxyProtocolException("invalid " + addrFamily + " address: " + address);
switch (addrFamily) {
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();
}
}

Expand Down

0 comments on commit 3ad96d6

Please sign in to comment.