-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
fix podman network inspect index check #12756
Conversation
@@ -232,11 +236,8 @@ func podmanNetworkInspect(name string) (netInfo, error) { | |||
|
|||
// results looks like 172.17.0.0/16,172.17.0.1,1500 | |||
vals := strings.Split(strings.TrimSpace(output), ",") | |||
if len(vals) == 0 { |
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.
we can still check for length zero, right?
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.
I removed that because if the second argument of Split
is non-empty, then it will always return a len of 1 or greater so the check will never be true.
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.
ah yeah i see what you're saying, we're checking for output empty above, could we check for strings.TrimSpace(output) == ""
just as a precaution?
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.
Yup, will update
Done
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: medyagh, spowelljr The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes #12489
Problem:
We had an incorrect len check, we'd check if the slice had at least one element, but then we'd try accessing the second (index 1) element, which may not exist, resulting in out of bounds exception being thrown.
Solution:
Fix len check and add test for the function.