Skip to content

fix podman network inspect index check#12756

Merged
medyagh merged 2 commits intokubernetes:masterfrom
spowelljr:fixNetworkIndex
Oct 25, 2021
Merged

fix podman network inspect index check#12756
medyagh merged 2 commits intokubernetes:masterfrom
spowelljr:fixNetworkIndex

Conversation

@spowelljr
Copy link
Copy Markdown
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

// 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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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

Details 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