Skip to content

Commit 17401b5

Browse files
sipsmatonistiigi
authored andcommitted
Fix buildkitd panic when frontend input is nil.
Signed-off-by: Erik Sipsma <[email protected]> (cherry picked from commit 2e6d0bf) Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 99aaa10 commit 17401b5

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

client/llb/definition.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ type DefinitionOp struct {
2929

3030
// NewDefinitionOp returns a new operation from a marshalled definition.
3131
func NewDefinitionOp(def *pb.Definition) (*DefinitionOp, error) {
32+
if def == nil {
33+
return nil, errors.New("invalid nil input definition to definition op")
34+
}
35+
3236
ops := make(map[digest.Digest]*pb.Op)
3337
defs := make(map[digest.Digest][]byte)
3438
platforms := make(map[digest.Digest]*ocispecs.Platform)

client/llb/definition_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,9 @@ func TestDefinitionInputCache(t *testing.T) {
118118
// 1 exec + 2x2 mounts from stA and stB + 1 src = 6 vertexes
119119
require.Equal(t, 6, len(vertexCache))
120120
}
121+
122+
func TestDefinitionNil(t *testing.T) {
123+
// should be an error, not a panic
124+
_, err := NewDefinitionOp(nil)
125+
require.Error(t, err)
126+
}

frontend/dockerfile/dockerfile_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ var allTests = integration.TestFuncs(
160160
testNilProvenance,
161161
testSBOMScannerArgs,
162162
testMultiPlatformWarnings,
163+
testNilContextInSolveGateway,
163164
)
164165

165166
// Tests that depend on the `security.*` entitlements
@@ -6600,6 +6601,29 @@ COPY --from=0 / /
66006601
require.Equal(t, expectedDigest, outDigest)
66016602
}
66026603

6604+
func testNilContextInSolveGateway(t *testing.T, sb integration.Sandbox) {
6605+
f := getFrontend(t, sb)
6606+
c, err := client.New(sb.Context(), sb.Address())
6607+
require.NoError(t, err)
6608+
defer c.Close()
6609+
6610+
_, err = c.Build(sb.Context(), client.SolveOpt{}, "", func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
6611+
res, err := f.SolveGateway(ctx, c, gateway.SolveRequest{
6612+
Frontend: "dockerfile.v0",
6613+
FrontendInputs: map[string]*pb.Definition{
6614+
builder.DefaultLocalNameDockerfile: nil,
6615+
builder.DefaultLocalNameContext: nil,
6616+
},
6617+
})
6618+
if err != nil {
6619+
return nil, err
6620+
}
6621+
return res, nil
6622+
}, nil)
6623+
// should not cause buildkitd to panic
6624+
require.ErrorContains(t, err, "invalid nil input definition to definition op")
6625+
}
6626+
66036627
func runShell(dir string, cmds ...string) error {
66046628
for _, args := range cmds {
66056629
var cmd *exec.Cmd

0 commit comments

Comments
 (0)