1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Avoid "invalid memory address or nil pointer dereference" panic

libcontainer.GetNamespace returns nil on FreeBSD because
libcontainer.namespaceList is empty. In this case, Namespaces#Get should
return nil instead of being panic.

Docker-DCO-1.1-Signed-off-by: Kato Kazuyoshi <kato.kazuyoshi@gmail.com> (github: kzys)
This commit is contained in:
Kato Kazuyoshi 2014-04-10 22:07:29 +09:00
parent 14e1a2345d
commit c5226d94fa
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) {