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

Prevent slice index out of range #84977

Closed
wants to merge 1 commit into from

Conversation

@ZP-AlwaysWin
Copy link
Contributor

ZP-AlwaysWin commented Nov 8, 2019

What type of PR is this?
Prevent slice index out of range

/kind cleanup

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

parts := versionMatchRE.FindStringSubmatch(str)
parts is a slice ,But its size is not guaranteed to be greater than 3
so parts[1].parts[2] is can panic: runtime error: index out of range

Previous code

parts := versionMatchRE.FindStringSubmatch(str)
if parts == nil {
	return nil, fmt.Errorf("could not parse %q as version", str)
}
numbers, extra := parts[1], parts[2]

Now Code

parts := versionMatchRE.FindStringSubmatch(str)
if len(parts) < 3 {
	return nil, fmt.Errorf("could not parse %q as version", str)
}
numbers, extra := parts[1], parts[2]

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented Nov 8, 2019

@ZP-AlwaysWin: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented Nov 8, 2019

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ZP-AlwaysWin
To complete the pull request process, please assign liggitt
You can assign the PR to them by writing /assign @liggitt in a comment when ready.

The full list of commands accepted by this bot can be found 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

@ZP-AlwaysWin

This comment has been minimized.

Copy link
Contributor Author

ZP-AlwaysWin commented Nov 8, 2019

/assign @ncdc

@ncdc

This comment has been minimized.

Copy link
Member

ncdc commented Nov 8, 2019

In my testing on the go playground, using various inputs, I'm only able to get nil or a 3-element array. What version string are you using that results in a panic?

@ZP-AlwaysWin ZP-AlwaysWin deleted the ZP-AlwaysWin:dev-1108 branch Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.