Skip to content

Commit 0d2f34a

Browse files
committed
Fix NPE when listing public IPs associated to removed networks or VPCs
1 parent 9ae696d commit 0d2f34a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import javax.inject.Inject;
4545
import javax.naming.ConfigurationException;
4646

47+
import com.cloud.network.vpc.VpcVO;
4748
import org.apache.cloudstack.acl.ControlledEntity;
4849
import org.apache.cloudstack.acl.SecurityChecker;
4950
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -2580,12 +2581,21 @@ public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListP
25802581
}
25812582

25822583
if (associatedNetworkId != null) {
2583-
_accountMgr.checkAccess(caller, null, false, networkDao.findById(associatedNetworkId));
2584-
sc.setParameters("associatedNetworkIdEq", associatedNetworkId);
2584+
NetworkVO associatedNetwork = networkDao.findById(associatedNetworkId);
2585+
2586+
if (associatedNetwork != null) {
2587+
_accountMgr.checkAccess(caller, null, false, associatedNetwork);
2588+
sc.setParameters("associatedNetworkIdEq", associatedNetworkId);
2589+
}
25852590
}
2591+
25862592
if (vpcId != null) {
2587-
_accountMgr.checkAccess(caller, null, false, _vpcDao.findById(vpcId));
2588-
sc.setParameters("vpcId", vpcId);
2593+
VpcVO vpc = _vpcDao.findById(vpcId);
2594+
2595+
if (vpc != null) {
2596+
_accountMgr.checkAccess(caller, null, false, vpc);
2597+
sc.setParameters("vpcId", vpcId);
2598+
}
25892599
}
25902600

25912601
addrs = _publicIpAddressDao.search(sc, searchFilter); // Allocated

0 commit comments

Comments
 (0)