Skip to content

Commit

Permalink
Merge pull request moby#47988 from vvoland/v23.0-47985
Browse files Browse the repository at this point in the history
[23.0 backport] builder/mobyexporter: Add missing nil check
  • Loading branch information
thaJeztah authored Jun 15, 2024
2 parents 907eb13 + eb75e3f commit b449180
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builder/builder-next/exporter/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History,
return nil, errors.Wrap(err, "failed to parse image config for patch")
}

if m == nil {
return nil, errors.New("null image config")
}

var rootFS ocispec.RootFS
rootFS.Type = "layers"
rootFS.DiffIDs = append(rootFS.DiffIDs, dps...)
Expand Down
42 changes: 42 additions & 0 deletions builder/builder-next/exporter/writer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package containerimage

import (
"testing"

"gotest.tools/v3/assert"
)

func TestPatchImageConfig(t *testing.T) {
for _, tc := range []struct {
name string
cfgJSON string
err string
}{
{
name: "empty",
cfgJSON: "{}",
},
{
name: "history only",
cfgJSON: `{"history": []}`,
},
{
name: "rootfs only",
cfgJSON: `{"rootfs": {}}`,
},
{
name: "null",
cfgJSON: "null",
err: "null image config",
},
} {
t.Run(tc.name, func(t *testing.T) {
_, err := patchImageConfig([]byte(tc.cfgJSON), nil, nil, nil, nil)
if tc.err == "" {
assert.NilError(t, err)
} else {
assert.ErrorContains(t, err, tc.err)
}
})
}
}

0 comments on commit b449180

Please sign in to comment.