-
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?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12372 +/- ##
============================================
- Coverage 17.76% 17.76% -0.01%
Complexity 15861 15861
============================================
Files 5923 5923
Lines 530470 530474 +4
Branches 64823 64825 +2
============================================
- Hits 94253 94251 -2
- Misses 425673 425678 +5
- Partials 10544 10545 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
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.
Pull request overview
This PR fixes a NullPointerException that occurs when listing public IP addresses with a removed network or VPC ID as a parameter. When a User account attempts to list IPs using a removed resource ID, the database query returns null, causing an NPE during access checks.
Key Changes
- Added null checks before accessing network and VPC objects when validating access permissions
- Search criteria parameters are now conditionally set only when the associated resource exists
- Added VpcVO import to support the VPC null check logic
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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); | ||
| } | ||
| } |
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.
|
|
||
| if (associatedNetwork != null) { | ||
| _accountMgr.checkAccess(caller, null, false, associatedNetwork); | ||
| sc.setParameters("associatedNetworkIdEq", associatedNetworkId); |
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.
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.
| sc.setParameters("associatedNetworkIdEq", associatedNetworkId); | |
| sc.setParameters("associatedNetworkIdEq", associatedNetworkId); | |
| } else { | |
| throw new InvalidParameterValueException("Unable to find network by id " + associatedNetworkId); |
| if (vpc != null) { | ||
| _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.
When a removed VPC ID is provided, the code silently skips the search parameter without informing the user. This creates inconsistent API behavior where a valid but removed VPC ID returns all public IPs instead of an empty result or an error. Consider throwing an InvalidParameterValueException when the VPC is not found to provide clearer feedback to the API caller.
| 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); |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16258 |
|
@erikbocks , would this also apply to version 20 and 22? (not just main?) |
Description
When listing public IPs associated to a network, the database query only considers records that are not marked as removed. If the ID of an removed resource is informed, a
nullvalue is returned in the database query. If the caller is aUsertype account, during the access checks the code tries to access one of the value's properties, resulting in anNullPointerException.A validation was added to this flow to prevent the property access when the resource is
null, and the listing behavior was standardized. The same validation was added to handle removed VPCs, as the same behavior was presented for them.Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
Screenshots (if appropriate):
Behavior before the change
Behavior after the change
How Has This Been Tested?
First, I created an isolated network, informing a public IP address to be assigned as the network's source NAT. After that, the network was removed. Then, I authenticated with an
Usertype account in CloudMonkey and called thelistPublicIpAddressesAPI, informing the removed network's UUID as theassociatednetworkidparameter. As expected, the exception was thrown.Exception stack trace in Management Server's logs
After applying the code with my changes to my local environment, the same steps were executed, and I validated that the behavior was fixed. The same steps were reproduced for removed VPCs.
The code was also compiled with tests on Maven.