From 2e0ceaa9352fb0f2399c1622fc814dcb87bc7b0b Mon Sep 17 00:00:00 2001 From: Neil Johnson Date: Mon, 4 Oct 2021 13:02:24 -0400 Subject: [PATCH] fix createDevices when no Linux section Signed-off-by: Neil Johnson --- libcontainer/specconv/spec_linux.go | 2 +- libcontainer/specconv/spec_linux_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go index eac6688aa..44b035a86 100644 --- a/libcontainer/specconv/spec_linux.go +++ b/libcontainer/specconv/spec_linux.go @@ -678,7 +678,7 @@ func createDevices(spec *specs.Spec, config *configs.Config) ([]*devices.Device, next: for _, ad := range AllowedDevices { - if ad.Path != "" { + if ad.Path != "" && spec.Linux != nil { for _, sd := range spec.Linux.Devices { if sd.Path == ad.Path { continue next diff --git a/libcontainer/specconv/spec_linux_test.go b/libcontainer/specconv/spec_linux_test.go index 963d803a6..567f55b53 100644 --- a/libcontainer/specconv/spec_linux_test.go +++ b/libcontainer/specconv/spec_linux_test.go @@ -546,6 +546,28 @@ func TestSpecconvExampleValidate(t *testing.T) { } } +func TestSpecconvNoLinuxSection(t *testing.T) { + spec := Example() + spec.Root.Path = "/" + spec.Linux = nil + spec.Hostname = "" + + opts := &CreateOpts{ + CgroupName: "ContainerID", + Spec: spec, + } + + config, err := CreateLibcontainerConfig(opts) + if err != nil { + t.Errorf("Couldn't create libcontainer config: %v", err) + } + + validator := validate.New() + if err := validator.Validate(config); err != nil { + t.Errorf("Expected specconv to produce valid container config: %v", err) + } +} + func TestDupNamespaces(t *testing.T) { spec := &specs.Spec{ Root: &specs.Root{