-
Notifications
You must be signed in to change notification settings - Fork 32
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 segfault in host-ctr #20
base: develop
Are you sure you want to change the base?
Conversation
The linter complains about seven locations with deprecated function calls. Six are calls to log.L or log.G, and one to a deprecated method in containerd. |
// ... not if the user has specified their own registry credentials for 'public.ecr.aws'; In that case we use the default resolver. | ||
if _, found := registryConfig.Credentials["public.ecr.aws"]; found { | ||
return defaultResolver | ||
if registryConfig != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the right behavior here to just return the defaultResolver if registryConfig
is nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case branch is "this is the public ECR," and (if possible) the code here is trying to get an auth token for the public ECR. So this if statement at the head of the case branch says "but hey, if registryConfig
has something to say about the public ECR, well, never mind, we will go with what registryConfig
says." Thus if registryConfig
is nil, I am treating it as registryConfig
does not have anything to say, and we should attempt to get the token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a comment is in order. Assuming that my version of "what this thing does" is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense. The diff didn't help here because the top of the function is what creates this defaultResolver
. After reading more of the context I see how this is the right way to solve this.
if registryConfig != nil { | ||
if _, ok := registryConfig.Mirrors[host]; ok { | ||
endpoints = registryConfig.Mirrors[host].Endpoints | ||
} else { | ||
endpoints = registryConfig.Mirrors["*"].Endpoints | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't you created a new problem that endpoints
can now be unset? I think we probably want the else clause to be for the first if statement:
if registryConfig != nil { | |
if _, ok := registryConfig.Mirrors[host]; ok { | |
endpoints = registryConfig.Mirrors[host].Endpoints | |
} else { | |
endpoints = registryConfig.Mirrors["*"].Endpoints | |
} | |
if registryConfig != nil { | |
if _, ok := registryConfig.Mirrors[host]; ok { | |
endpoints = registryConfig.Mirrors[host].Endpoints | |
} | |
} else { | |
endpoints = registryConfig.Mirrors["*"].Endpoints | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, another good candidate for a comment. We start with an empty array of endpoints. Then we may replace that empty array with a non-empty one if registryConfig has an override. Then we append docker.defaultHost(host)
to the array. The endpoints array always has at least that one docker.defaultHost()
entry.
ea52f92
to
42f2742
Compare
I have added comments, hoping to make the code a little less opaque. |
I think I got myself confused a bit reviewing this code so I went digging, I wonder if the right fix is to ensure https://github.com/bottlerocket-os/bottlerocket-core-kit/blob/develop/sources/host-ctr/cmd/host-ctr/main.go#L1025 doesn't proceed as an uninitialized variable if |
Yes, I think it makes sense to build an empty |
Bottlerocket invokes the host-ctr executable with an optional "--registry-config" parameter. If this parameter was omitted (for instance, in customer code), host-ctr would segfault. Now it will behave as it would for an empty registry-config file.
42f2742
to
64cda91
Compare
Updated: added a Tested manually using the same |
// ... not if the user has specified their own registry credentials for 'public.ecr.aws'; In that case we use the default resolver. | ||
if _, found := registryConfig.Credentials["public.ecr.aws"]; found { | ||
return defaultResolver | ||
if registryConfig != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense. The diff didn't help here because the top of the function is what creates this defaultResolver
. After reading more of the context I see how this is the right way to solve this.
Bottlerocket invokes the host-ctr executable with an optional "--registry-config" parameter. If this parameter was omitted (for instance, in customer code), host-ctr would segfault. Now it will behave as it would for an empty registry-config file.
Issue number:
Closes #4059
Description of changes:
Protect two locations where we tried to dereference the registryConfig pointer. The pointer is nil if host-ctr is invoked
without the optional
--registry-config
parameter.Testing done:
Built an image and demonstrated that the command in issue #4059 could load a container from a public ECR repository without segfaulting.
Terms of contribution:
By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.