Skip to content
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

Merged
merged 2 commits into from
Oct 25, 2021

Conversation

spowelljr
Copy link
Member

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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 21, 2021
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 21, 2021
@@ -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 {
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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?

Copy link
Member Author

@spowelljr spowelljr Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, will update

Done

@medyagh medyagh merged commit 27b0c74 into kubernetes:master Oct 25, 2021
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@spowelljr spowelljr deleted the fixNetworkIndex branch October 25, 2021 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

minikube start with podman driver fails with index ouf range error
4 participants