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

A bug that mutates a not-used copy of a struct #105423

Closed
guodongli-google opened this issue Oct 3, 2021 · 7 comments
Closed

A bug that mutates a not-used copy of a struct #105423

guodongli-google opened this issue Oct 3, 2021 · 7 comments
Assignees
Labels
area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework kind/bug Categorizes issue or PR as related to a bug. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@guodongli-google
Copy link

What happened:

A static analyzer DeepGo reports a finding that reveals a coding issue.

What you expected to happen:

At https://github.com/kubernetes/kubernetes/blob/master/vendor/github.com/emicklei/go-restful/route.go#L168-L169

Here Route is struct which will be copied by value. The mutation on the value receiver r doesn't do anything to the original struct in the caller. As a consequence, this mutation has no meaningful effect.

type Route struct {
	Method   string
	...
	contentEncodingEnabled *bool
}

func (r Route) EnableContentEncoding(enabled bool) {
	r.contentEncodingEnabled = &enabled
}

One fix is to use pointer receiver.

func (r *Route) EnableContentEncoding(enabled bool) {
	r.contentEncodingEnabled = &enabled
}

Another possible fix is to write back enabled into the caller'scontentEncodingEnabled :

func (r Route) EnableContentEncoding(enabled bool) {
	*r.contentEncodingEnabled = enabled
}

How to reproduce it (as minimally and precisely as possible):

A simplified bug reproducer is available at: https://play.golang.org/p/cibNCyIarZS

Anything else we need to know?:

Related issue: #105155

Found by #deepgo.

@guodongli-google guodongli-google added the kind/bug Categorizes issue or PR as related to a bug. label Oct 3, 2021
@k8s-ci-robot k8s-ci-robot added needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 3, 2021
@shivanshuraj1333
Copy link
Contributor

/triage accepted
/area e2e-test-framework
/sig testing

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 3, 2021
@shivanshuraj1333
Copy link
Contributor

/remove-sig testing

@k8s-ci-robot k8s-ci-robot added needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. and removed sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Oct 3, 2021
@k8s-ci-robot
Copy link
Contributor

@guodongli-google: There are no sig labels on this issue. Please add an appropriate label by using one of the following commands:

  • /sig <group-name>
  • /wg <group-name>
  • /committee <group-name>

Please see the group list for a listing of the SIGs, working groups, and committees available.

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.

@shivanshuraj1333
Copy link
Contributor

/assign

@shivanshuraj1333
Copy link
Contributor

Filled the bug in the vendor's repository, we can close this now @guodongli-google

@neolit123
Copy link
Member

looks like EnableContentEncoding() is not used by k/k code too.

/close

@k8s-ci-robot
Copy link
Contributor

@neolit123: Closing this issue.

In response to this:

looks like EnableContentEncoding() is not used by k/k code too.

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework kind/bug Categorizes issue or PR as related to a bug. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants