diff --git a/volume/mounts/lcow_parser.go b/volume/mounts/lcow_parser.go index c572349c8a..2dbd2d164b 100644 --- a/volume/mounts/lcow_parser.go +++ b/volume/mounts/lcow_parser.go @@ -2,8 +2,10 @@ package mounts // import "github.com/docker/docker/volume/mounts" import ( "errors" + "fmt" "path" "regexp" + "strings" "github.com/docker/docker/api/types/mount" ) @@ -37,8 +39,8 @@ var lcowValidators mountValidator = func(m *mount.Mount) error { if m.Type == mount.TypeNamedPipe { return errors.New("Linux containers on Windows do not support named pipe mounts") } - if err := windowsValidateRegex(m.Target, lcowMountDestinationRegex); err != nil { - return err + if !lcowMountDestinationRegex.MatchString(strings.ToLower(m.Target)) { + return fmt.Errorf("invalid mount path: '%s'", m.Target) } return nil } diff --git a/volume/mounts/windows_parser.go b/volume/mounts/windows_parser.go index a3157105f8..4beee769d7 100644 --- a/volume/mounts/windows_parser.go +++ b/volume/mounts/windows_parser.go @@ -155,17 +155,14 @@ var windowsValidators mountValidator = func(m *mount.Mount) error { if err := windowsValidateNotRoot(m.Target); err != nil { return err } - return windowsValidateRegex(m.Target, mountDestinationRegexp) + if !mountDestinationRegexp.MatchString(strings.ToLower(m.Target)) { + return fmt.Errorf("invalid mount path: '%s'", m.Target) + } + return nil } -func windowsValidateRegex(p string, r *regexp.Regexp) error { - if r.MatchString(strings.ToLower(p)) { - return nil - } - return fmt.Errorf("invalid mount path: '%s'", p) -} func windowsValidateAbsolute(p string) error { - if err := windowsValidateRegex(p, mountDestinationRegexp); err != nil { + if !mountDestinationRegexp.MatchString(strings.ToLower(p)) { return fmt.Errorf("invalid mount path: '%s' mount path must be absolute", p) } return nil