6161import javax .net .ssl .SSLContext ;
6262import javax .net .ssl .TrustManager ;
6363
64+ import com .cloud .network .vpc .VpcVO ;
6465import org .apache .cloudstack .acl .ControlledEntity ;
6566import org .apache .cloudstack .acl .SecurityChecker ;
6667import org .apache .cloudstack .affinity .AffinityGroupProcessor ;
@@ -5347,12 +5348,21 @@ public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListP
53475348 }
53485349
53495350 if (associatedNetworkId != null ) {
5350- _accountMgr .checkAccess (caller , null , false , networkDao .findById (associatedNetworkId ));
5351- sc .setParameters ("associatedNetworkIdEq" , associatedNetworkId );
5351+ NetworkVO associatedNetwork = networkDao .findById (associatedNetworkId );
5352+
5353+ if (associatedNetwork != null ) {
5354+ _accountMgr .checkAccess (caller , null , false , associatedNetwork );
5355+ sc .setParameters ("associatedNetworkIdEq" , associatedNetworkId );
5356+ }
53525357 }
5358+
53535359 if (vpcId != null ) {
5354- _accountMgr .checkAccess (caller , null , false , _vpcDao .findById (vpcId ));
5355- sc .setParameters ("vpcId" , vpcId );
5360+ VpcVO vpc = _vpcDao .findById (vpcId );
5361+
5362+ if (vpc != null ) {
5363+ _accountMgr .checkAccess (caller , null , false , vpc );
5364+ sc .setParameters ("vpcId" , vpcId );
5365+ }
53565366 }
53575367
53585368 addrs = _publicIpAddressDao .search (sc , searchFilter ); // Allocated
@@ -5369,13 +5379,16 @@ public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListP
53695379 }
53705380 if (associatedNetworkId != null ) {
53715381 NetworkVO guestNetwork = networkDao .findById (associatedNetworkId );
5372- if (zoneId == null ) {
5373- zoneId = guestNetwork .getDataCenterId ();
5374- } else if (zoneId != guestNetwork .getDataCenterId ()) {
5375- InvalidParameterValueException ex = new InvalidParameterValueException ("Please specify a valid associated network id in the specified zone." );
5376- throw ex ;
5382+
5383+ if (guestNetwork != null ) {
5384+ if (zoneId == null ) {
5385+ zoneId = guestNetwork .getDataCenterId ();
5386+ } else if (zoneId != guestNetwork .getDataCenterId ()) {
5387+ InvalidParameterValueException ex = new InvalidParameterValueException ("Please specify a valid associated network id in the specified zone." );
5388+ throw ex ;
5389+ }
5390+ owner = _accountDao .findById (guestNetwork .getAccountId ());
53775391 }
5378- owner = _accountDao .findById (guestNetwork .getAccountId ());
53795392 }
53805393 List <DataCenterVO > dcList = new ArrayList <>();
53815394 if (zoneId == null ){
0 commit comments