-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix NPE during public IP listing when a removed network or VPC ID is informed for associatenetworkid parameter #12372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,7 @@ | |||||||||||||||||||||
| 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; | ||||||||||||||||||||||
|
|
@@ -2648,12 +2649,21 @@ public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListP | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| 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); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+2663
to
+2666
|
||||||||||||||||||||||
| if (vpc != null) { | |
| _accountMgr.checkAccess(caller, null, false, vpc); | |
| sc.setParameters("vpcId", vpcId); | |
| } | |
| if (vpc == null) { | |
| throw new InvalidParameterValueException("Unable to find VPC by id " + vpcId); | |
| } | |
| _accountMgr.checkAccess(caller, null, false, vpc); | |
| sc.setParameters("vpcId", vpcId); |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix for the NPE is incomplete. While null checks are added for associatedNetworkId and vpcId here, there's no test coverage for these specific scenarios. Since ManagementServerImplTest already has tests for the setParameters method with ListPublicIpAddressesCmd, consider adding tests that verify the behavior when removed network/VPC IDs are provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a removed network ID is provided, the code silently skips the search parameter without informing the user. This creates inconsistent API behavior where a valid but removed network ID returns all public IPs instead of an empty result or an error. Consider throwing an InvalidParameterValueException when the network is not found to provide clearer feedback to the API caller.