Fix NPE during public IP listing when a removed network or VPC ID is informed for associatenetworkid parameter (#12372)

This commit is contained in:
Erik Böck 2026-02-23 09:03:36 -03:00 committed by GitHub
parent cf71938473
commit c748b69e70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 10 deletions

View File

@ -44,6 +44,7 @@ import javax.crypto.spec.SecretKeySpec;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.network.vpc.VpcVO;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@ -2580,12 +2581,21 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
}
if (associatedNetworkId != null) {
_accountMgr.checkAccess(caller, null, false, networkDao.findById(associatedNetworkId));
sc.setParameters("associatedNetworkIdEq", associatedNetworkId);
NetworkVO associatedNetwork = networkDao.findById(associatedNetworkId);
if (associatedNetwork != null) {
_accountMgr.checkAccess(caller, null, false, associatedNetwork);
sc.setParameters("associatedNetworkIdEq", associatedNetworkId);
}
}
if (vpcId != null) {
_accountMgr.checkAccess(caller, null, false, _vpcDao.findById(vpcId));
sc.setParameters("vpcId", vpcId);
VpcVO vpc = _vpcDao.findById(vpcId);
if (vpc != null) {
_accountMgr.checkAccess(caller, null, false, vpc);
sc.setParameters("vpcId", vpcId);
}
}
addrs = _publicIpAddressDao.search(sc, searchFilter); // Allocated
@ -2602,13 +2612,16 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
}
if (associatedNetworkId != null) {
NetworkVO guestNetwork = networkDao.findById(associatedNetworkId);
if (zoneId == null) {
zoneId = guestNetwork.getDataCenterId();
} else if (zoneId != guestNetwork.getDataCenterId()) {
InvalidParameterValueException ex = new InvalidParameterValueException("Please specify a valid associated network id in the specified zone.");
throw ex;
if (guestNetwork != null) {
if (zoneId == null) {
zoneId = guestNetwork.getDataCenterId();
} else if (zoneId != guestNetwork.getDataCenterId()) {
InvalidParameterValueException ex = new InvalidParameterValueException("Please specify a valid associated network id in the specified zone.");
throw ex;
}
owner = _accountDao.findById(guestNetwork.getAccountId());
}
owner = _accountDao.findById(guestNetwork.getAccountId());
}
List<DataCenterVO> dcList = new ArrayList<>();
if (zoneId == null){