From f8eb8cc9825455bfdfae6ecb80ee97fd1f768c91 Mon Sep 17 00:00:00 2001 From: Bas van der Lei Date: Fri, 2 Oct 2015 13:49:27 +0200 Subject: [PATCH] validate name with isContainerName func --- container/docker/factory.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/container/docker/factory.go b/container/docker/factory.go index ef2b4d4c..c07f4445 100644 --- a/container/docker/factory.go +++ b/container/docker/factory.go @@ -131,14 +131,20 @@ func ContainerNameToDockerId(name string) string { return id } +func isContainerName(name string) bool { + if UseSystemd() { + return dockerCgroupRegexp.MatchString(path.Base(name)) + } + return true +} + // Docker handles all containers under /docker func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) { // docker factory accepts all containers it can handle. canAccept := true - // When using Systemd all docker containers have a .scope suffix - if UseSystemd() && !strings.HasSuffix(path.Base(name), ".scope") { - return false, canAccept, nil + if !isContainerName(name) { + return false, canAccept, fmt.Errorf("invalid container name") } // Check if the container is known to docker and it is active.