Skip to content

Commit

Permalink
Merge pull request #390 from tiborvass/fix-nil-labels-panic
Browse files Browse the repository at this point in the history
dockerfile: ensure Labels map is not accessed when nil
  • Loading branch information
AkihiroSuda authored May 17, 2018
2 parents c4bffb7 + a2d2551 commit 80f1131
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
}
}

if len(opt.Labels) != 0 && target.image.Config.Labels == nil {
target.image.Config.Labels = make(map[string]string, len(opt.Labels))
}
for k, v := range opt.Labels {
target.image.Config.Labels[k] = v
}
Expand Down Expand Up @@ -525,7 +528,7 @@ func dispatchMaintainer(d *dispatchState, c *instructions.MaintainerCommand) err
func dispatchLabel(d *dispatchState, c *instructions.LabelCommand) error {
commitMessage := bytes.NewBufferString("LABEL")
if d.image.Config.Labels == nil {
d.image.Config.Labels = make(map[string]string)
d.image.Config.Labels = make(map[string]string, len(c.Labels))
}
for _, v := range c.Labels {
d.image.Config.Labels[v.Key] = v.Value
Expand Down

0 comments on commit 80f1131

Please sign in to comment.