From 4fae8fcce2ee889e4e7b21c53a64aba0f9b87e3f Mon Sep 17 00:00:00 2001 From: Lifubang Date: Mon, 3 Sep 2018 23:27:31 +0800 Subject: [PATCH] code optimization after review Signed-off-by: Lifubang --- libcontainer/factory_linux.go | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index 14e998b4f..71712428b 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -359,23 +359,7 @@ func (l *LinuxFactory) loadState(root, id string) (*State, error) { } func (l *LinuxFactory) validateID(id string) error { - if !idRegex.MatchString(id) || id == ".." || id == "." { - return newGenericError(fmt.Errorf("invalid id format: %v", id), InvalidIdFormat) - } - - //For unforeseen invalid id situations, can checked by is SubDir? - rootPath, err := filepath.Abs(l.Root) - if err != nil { - return err - } - - containerRoot := filepath.Join(l.Root, id) - rootCheckPath, err := filepath.Abs(filepath.Join(containerRoot, "..")) - if err != nil { - return err - } - - if rootPath != rootCheckPath { + if id == "." || !idRegex.MatchString(id) || utils.CleanPath(id) != id { return newGenericError(fmt.Errorf("invalid id format: %v", id), InvalidIdFormat) }