Skip to content

Commit

Permalink
Fix buildkitd panic when frontend input is nil.
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
(cherry picked from commit 2e6d0bf)
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
sipsma authored and tonistiigi committed Feb 28, 2023
1 parent 99aaa10 commit 17401b5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/llb/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type DefinitionOp struct {

// NewDefinitionOp returns a new operation from a marshalled definition.
func NewDefinitionOp(def *pb.Definition) (*DefinitionOp, error) {
if def == nil {
return nil, errors.New("invalid nil input definition to definition op")
}

ops := make(map[digest.Digest]*pb.Op)
defs := make(map[digest.Digest][]byte)
platforms := make(map[digest.Digest]*ocispecs.Platform)
Expand Down
6 changes: 6 additions & 0 deletions client/llb/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ func TestDefinitionInputCache(t *testing.T) {
// 1 exec + 2x2 mounts from stA and stB + 1 src = 6 vertexes
require.Equal(t, 6, len(vertexCache))
}

func TestDefinitionNil(t *testing.T) {
// should be an error, not a panic
_, err := NewDefinitionOp(nil)
require.Error(t, err)
}
24 changes: 24 additions & 0 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ var allTests = integration.TestFuncs(
testNilProvenance,
testSBOMScannerArgs,
testMultiPlatformWarnings,
testNilContextInSolveGateway,
)

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

func testNilContextInSolveGateway(t *testing.T, sb integration.Sandbox) {
f := getFrontend(t, sb)
c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

_, err = c.Build(sb.Context(), client.SolveOpt{}, "", func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
res, err := f.SolveGateway(ctx, c, gateway.SolveRequest{
Frontend: "dockerfile.v0",
FrontendInputs: map[string]*pb.Definition{
builder.DefaultLocalNameDockerfile: nil,
builder.DefaultLocalNameContext: nil,
},
})
if err != nil {
return nil, err
}
return res, nil
}, nil)
// should not cause buildkitd to panic
require.ErrorContains(t, err, "invalid nil input definition to definition op")
}

func runShell(dir string, cmds ...string) error {
for _, args := range cmds {
var cmd *exec.Cmd
Expand Down

0 comments on commit 17401b5

Please sign in to comment.