From aa2fb311124599113ee73e00b583683976be615f Mon Sep 17 00:00:00 2001 From: Kishan Kavala Date: Wed, 5 Jun 2013 16:40:24 +0530 Subject: [PATCH] check for null protocol while validating ACL item --- .../network/vpc/NetworkACLServiceImpl.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java index d6e86e2c811..4ad22d90770 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java @@ -303,28 +303,30 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } //Validate Protocol - //Check if protocol is a number - if(StringUtils.isNumeric(protocol)){ - int protoNumber = Integer.parseInt(protocol); - if(protoNumber < 0 || protoNumber > 255){ - throw new InvalidParameterValueException("Invalid protocol number: " + protoNumber); + if(protocol != null){ + //Check if protocol is a number + if(StringUtils.isNumeric(protocol)){ + int protoNumber = Integer.parseInt(protocol); + if(protoNumber < 0 || protoNumber > 255){ + throw new InvalidParameterValueException("Invalid protocol number: " + protoNumber); + } + } else { + //Protocol is not number + //Check for valid protocol strings + String supportedProtocols = "tcp,udp,icmp,all"; + if(!supportedProtocols.contains(protocol.toLowerCase())){ + throw new InvalidParameterValueException("Invalid protocol: " + protocol); + } } - } else { - //Protocol is not number - //Check for valid protocol strings - String supportedProtocols = "tcp,udp,icmp,all"; - if(!supportedProtocols.contains(protocol.toLowerCase())){ - throw new InvalidParameterValueException("Invalid protocol: " + protocol); + + // icmp code and icmp type can't be passed in for any other protocol rather than icmp + if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != null || icmpType != null)) { + throw new InvalidParameterValueException("Can specify icmpCode and icmpType for ICMP protocol only"); } - } - // icmp code and icmp type can't be passed in for any other protocol rather than icmp - if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != null || icmpType != null)) { - throw new InvalidParameterValueException("Can specify icmpCode and icmpType for ICMP protocol only"); - } - - if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != null || portEnd != null)) { - throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP"); + if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != null || portEnd != null)) { + throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP"); + } } //validate icmp code and type