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

grpcclient: return proper nil reference from grpcclient #5406

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

jsternberg
Copy link
Collaborator

The grpcclient would take an empty reference and convert it into a (*reference)(nil) and then store that in a client.Reference. This caused the nil check in convertRef to return false because it wasn't nil but then it panicked because it was nil.

newReference has been minorly refactored to not return an error. The method is not exported, the error value is not used, and it obscured the functionality which made it harder to use correctly.

Fixes #5379.

@thompson-shaun thompson-shaun added this to the v0.17.0 milestone Oct 8, 2024
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

@jsternberg Did you find out if this was a regression from some change?

@jsternberg
Copy link
Collaborator Author

I don't know if it's reproducible there because I haven't tried, but I was able to find code that would cause the incorrect behavior as far back as when this feature was first introduced in 2018.

303b5da#diff-7cafce0d1cc08d47c233e73305faeccde66a98cd2b952b71d1c06df4de54ce58R229-R237

It's not as obvious in that snippet, but this part:

ref := &reference{id: v, c: c}
if v == "" {
	ref = nil
}
res.AddRef(k, ref)

The ref is a *reference because that's what type inference will give it and the nil is a nil *reference. AddRef takes an interface which would trigger the bug. This code got refactored at some point but it kept the same problem.

@tonistiigi
Copy link
Member

Can we add an integration test for this case as well.

@jsternberg
Copy link
Collaborator Author

Added an integration test and verified that it fails without the fix. I also found another code path that had the same problem in the RefsDeprecated branch and fixed that one up too.

The grpcclient would take an empty reference and convert it into a
`(*reference)(nil)` and then store that in a `client.Reference`. This
caused the `nil` check in `convertRef` to return false because it wasn't
`nil` but then it panicked because it was `nil`.

`newReference` has been minorly refactored to not return an error. The
method is not exported, the error value is not used, and it obscured the
functionality which made it harder to use correctly.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@tonistiigi tonistiigi merged commit 0bb688c into moby:master Oct 8, 2024
91 checks passed
@jsternberg jsternberg deleted the client-nil-reference branch October 8, 2024 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants