Check that mounts always have a target.

Otherwise the daemon panics when generating the OCI spec.

For belt and braces check in the ExecOp Run function but also when generating the spec.

Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
Ian Campbell
2018-03-21 17:04:43 +00:00
parent 3e90755493
commit ac6598d255
3 changed files with 40 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ func TestClientIntegration(t *testing.T) {
testWhiteoutParentDir,
testDuplicateWhiteouts,
testSchema1Image,
testMountWithNoSource,
})
}
@@ -705,6 +706,37 @@ func testSchema1Image(t *testing.T, sb integration.Sandbox) {
checkAllReleasable(t, c, sb, true)
}
// #319
func testMountWithNoSource(t *testing.T, sb integration.Sandbox) {
t.Parallel()
c, err := New(sb.Address())
require.NoError(t, err)
defer c.Close()
busybox := llb.Image("docker.io/library/busybox:latest")
st := llb.Scratch()
var nilState llb.State
// This should never actually be run, but we want to succeed
// if it was, because we expect an error below, or a daemon
// panic if the issue has regressed.
run := busybox.Run(
llb.Args([]string{"/bin/true"}),
llb.AddMount("/nil", nilState, llb.SourcePath("/"), llb.Readonly))
st = run.AddMount("/mnt", st)
def, err := st.Marshal()
require.NoError(t, err)
err = c.Solve(context.TODO(), def, SolveOpt{}, nil)
require.Error(t, err)
require.Contains(t, err.Error(), "has no input")
checkAllReleasable(t, c, sb, true)
}
func requiresLinux(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skipf("unsupported GOOS: %s", runtime.GOOS)

View File

@@ -50,6 +50,9 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
sm := &submounts{}
for _, m := range mounts {
if m.Src == nil {
return nil, nil, errors.Errorf("mount %s has no source", m.Dest)
}
mounts, err := m.Src.Mount(ctx, m.Readonly)
if err != nil {
sm.cleanup()

View File

@@ -95,6 +95,11 @@ func (e *execOp) Run(ctx context.Context, inputs []solver.Ref) ([]solver.Ref, er
mountable = active
}
}
if mountable == nil {
return nil, errors.Errorf("mount %s has no input", m.Dest)
}
if m.Dest == pb.RootMount {
root = mountable
} else {