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

solver: forward nil return value from sharedOp.Exec #3043

Merged
merged 1 commit into from Aug 22, 2022

Conversation

jedevc
Copy link
Member

@jedevc jedevc commented Aug 18, 2022

Fixes #3040

Exec could sometimes return nil, which would then result in a segmentation fault, as the code attempts to access a field in the nil
result to return. This patch introduces a sanity check before accessing any parts of the field.

solver/jobs.go Outdated
@@ -872,6 +872,9 @@ func (s *sharedOp) Exec(ctx context.Context, inputs []Result) (outputs []Result,
return nil, nil, err
}
r := res.(*execRes)
if r == nil {
Copy link
Member

Choose a reason for hiding this comment

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

This looks correct but is quite a weird construction. Normally typed nil should be avoided and res=nil should be checked. Maybe a comment saying "callback to s.g.Do guarantees that res is always typed *execRes if err or res is nil" would help.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's a weird construction. I've reworked the code so that we can just check res==nil.

To do that, I've changed how the method above handles returns - returning s.execRes when s.execRes == nil is not the same as just returning nil, and the new code distinguishes between these two cases.

Exec could sometimes return nil, which would then result in a
segmentation fault, as the code attempts to access a field in the nil
result to return. This patch introduces a sanity check before accessing
any parts of the field.

Signed-off-by: Justin Chadwell <me@jedevc.com>
@tonistiigi tonistiigi merged commit b50172e into moby:master Aug 22, 2022
return nil, s.execErr
}
if s.execRes != nil {
return s.execRes, nil
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this does not atm cache the nil value correctly and Exec gets called again in that case. This can be addressed in follow up.

Is the only case where this can return nil when loading an image without any layers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

buildkitd SIGSEGV
3 participants