Skip to content

Commit db4940c

Browse files
server: avoid NPE updating a network ACL rule with no protocol
On a full (non-partial) network ACL item update, transferDataToNetworkAclRulePojo clears the protocol to null before updateIcmpCodeAndTypeFullUpgrade runs, and that method called networkACLItemVo.getProtocol().equalsIgnoreCase(...) on the null protocol, throwing NullPointerException. A full upgrade with no protocol is a valid input: the parameter is optional and the mode is meant to disregard the current configuration. Compare against the constant first so a null protocol falls through to clearing the icmp fields.
1 parent 2cd8c5e commit db4940c

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ protected void updateIcmpCodeAndType (boolean isPartialUpgrade, UpdateNetworkACL
946946
}
947947

948948
private void updateIcmpCodeAndTypeFullUpgrade (Integer icmpCode, Integer icmpType, NetworkACLItemVO networkACLItemVo) {
949-
if (networkACLItemVo.getProtocol().equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
949+
if (NetUtils.ICMP_PROTO.equalsIgnoreCase(networkACLItemVo.getProtocol())) {
950950
networkACLItemVo.setIcmpCode(icmpCode != null ? icmpCode : -1);
951951
networkACLItemVo.setIcmpType(icmpType != null ? icmpType : -1);
952952
} else {

server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.cloudstack.context.CallContext;
4646
import org.apache.commons.lang3.StringUtils;
4747
import org.junit.Assert;
48+
import org.springframework.test.util.ReflectionTestUtils;
4849
import org.junit.Before;
4950
import org.junit.Test;
5051
import org.junit.runner.RunWith;
@@ -1506,4 +1507,16 @@ public void validateAclAssociatedToVpcTestNullVpcShouldThrowInvalidParameterValu
15061507

15071508
networkAclServiceImpl.validateAclAssociatedToVpc(networkMockVpcMockId, accountMock, SOME_UUID);
15081509
}
1510+
1511+
@Test
1512+
public void updateIcmpCodeAndTypeFullUpgradeHandlesNullProtocol() {
1513+
NetworkACLItemVO rule = new NetworkACLItemVO();
1514+
rule.setIcmpCode(5);
1515+
rule.setIcmpType(8);
1516+
1517+
ReflectionTestUtils.invokeMethod(networkAclServiceImpl, "updateIcmpCodeAndTypeFullUpgrade", 1, 2, rule);
1518+
1519+
Assert.assertNull(rule.getIcmpCode());
1520+
Assert.assertNull(rule.getIcmpType());
1521+
}
15091522
}

0 commit comments

Comments
 (0)