Skip to content

Commit

Permalink
solver: forward nil return value from sharedOp.Exec
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jedevc committed Aug 19, 2022
1 parent 55ba9d1 commit c58f128
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions solver/jobs.go
Expand Up @@ -817,8 +817,11 @@ func (s *sharedOp) Exec(ctx context.Context, inputs []Result) (outputs []Result,
}
flightControlKey := "exec"
res, err := s.g.Do(ctx, flightControlKey, func(ctx context.Context) (ret interface{}, retErr error) {
if s.execRes != nil || s.execErr != nil {
return s.execRes, s.execErr
if s.execErr != nil {
return nil, s.execErr
}
if s.execRes != nil {
return s.execRes, nil
}
release, err := op.Acquire(ctx)
if err != nil {
Expand Down Expand Up @@ -866,9 +869,12 @@ func (s *sharedOp) Exec(ctx context.Context, inputs []Result) (outputs []Result,
}
s.execErr = err
}
return s.execRes, err
if s.execRes == nil || err != nil {
return nil, err
}
return s.execRes, nil
})
if err != nil {
if res == nil || err != nil {
return nil, nil, err
}
r := res.(*execRes)
Expand Down

0 comments on commit c58f128

Please sign in to comment.