Merge pull request #5143 from kzys/ns-nil

Avoid "invalid memory address or nil pointer dereference" panic
This commit is contained in:
Victor Vieux 2014-04-10 11:07:35 -07:00
commit 0868f77370
2 changed files with 10 additions and 1 deletions

View File

@ -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
}
}

View File

@ -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) {