diff --git a/libcontainer/types.go b/libcontainer/types.go index ffeb55a..d4818c3 100644 --- a/libcontainer/types.go +++ b/libcontainer/types.go @@ -68,7 +68,7 @@ func (n Namespaces) Contains(ns string) bool { func (n Namespaces) Get(ns string) *Namespace { for _, nsp := range n { - if nsp.Key == ns { + if nsp != nil && nsp.Key == ns { return nsp } } diff --git a/libcontainer/types_test.go b/libcontainer/types_test.go index 9735937..dd31298 100644 --- a/libcontainer/types_test.go +++ b/libcontainer/types_test.go @@ -18,6 +18,15 @@ func TestNamespacesContains(t *testing.T) { if !ns.Contains("NEWPID") { t.Fatal("namespaces should contain NEWPID but does not") } + + withNil := Namespaces{ + GetNamespace("UNDEFINED"), // this element will be nil + GetNamespace("NEWPID"), + } + + if !withNil.Contains("NEWPID") { + t.Fatal("namespaces should contain NEWPID but does not") + } } func TestCapabilitiesContains(t *testing.T) {