Skip to content

Commit

Permalink
fix a possible panic on cache
Browse files Browse the repository at this point in the history
```
newDesc.Annotations = nil
for _, k := range addAnnotations {
  newDesc.Annotations[k] = desc.Annotations[k]
}
```

The codes may cause buildkitd panic: assignment to entry in nil map

Signed-off-by: Yan Song <imeoer@linux.alibaba.com>
(cherry picked from commit 39bd8c6)
  • Loading branch information
imeoer authored and tonistiigi committed Feb 28, 2023
1 parent c327eb8 commit 99aaa10
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cache/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ func (sr *immutableRef) getRemote(ctx context.Context, createIfNeeded bool, refC
newDesc.Size = blobDesc.Size
newDesc.URLs = blobDesc.URLs
newDesc.Annotations = nil
if len(addAnnotations) > 0 || len(blobDesc.Annotations) > 0 {
newDesc.Annotations = make(map[string]string)
}
for _, k := range addAnnotations {
newDesc.Annotations[k] = desc.Annotations[k]
}
for k, v := range blobDesc.Annotations {
if newDesc.Annotations == nil {
newDesc.Annotations = make(map[string]string)
}
newDesc.Annotations[k] = v
}
desc = newDesc
Expand Down

0 comments on commit 99aaa10

Please sign in to comment.