diff --git a/daemon/checkpoint.go b/daemon/checkpoint.go index 417ae59f2d0229e6572e9989d0874d897016e781..27181743f54bae60db71d357ee587ed059df22bb 100644 --- a/daemon/checkpoint.go +++ b/daemon/checkpoint.go @@ -8,6 +8,12 @@ import ( "path/filepath" "github.com/docker/docker/api/types" + "github.com/docker/docker/utils" +) + +var ( + validCheckpointNameChars = utils.RestrictedNameChars + validCheckpointNamePattern = utils.RestrictedNamePattern ) // CheckpointCreate checkpoints the process running in a container with CRIU @@ -28,6 +34,10 @@ func (daemon *Daemon) CheckpointCreate(name string, config types.CheckpointCreat checkpointDir = container.CheckpointDir() } + if !validCheckpointNamePattern.MatchString(config.CheckpointID) { + return fmt.Errorf("Invalid checkpoint ID (%s), only %s are allowed", config.CheckpointID, validCheckpointNameChars) + } + err = daemon.containerd.CreateCheckpoint(container.ID, config.CheckpointID, checkpointDir, config.Exit) if err != nil { return fmt.Errorf("Cannot checkpoint container %s: %s", name, err) diff --git a/daemon/names.go b/daemon/names.go index 19e78cc17316b0b281356f3d498938191e53a574..273d551513b809ff2a763ddeb21579408d5bb60d 100644 --- a/daemon/names.go +++ b/daemon/names.go @@ -2,6 +2,7 @@ package daemon import ( "fmt" + "strings" "github.com/Sirupsen/logrus" "github.com/docker/docker/container" @@ -58,7 +59,7 @@ func (daemon *Daemon) generateIDAndName(name string) (string, string, error) { } func (daemon *Daemon) reserveName(id, name string) (string, error) { - if !validContainerNamePattern.MatchString(name) { + if !validContainerNamePattern.MatchString(strings.TrimPrefix(name, "/")) { return "", fmt.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars) } if name[0] != '/' { diff --git a/utils/names.go b/utils/names.go index 8239c0de297e806ba51902a28dd0bb8e55b53138..632062819c9f685a4c8c051674fd51f30a4914c8 100644 --- a/utils/names.go +++ b/utils/names.go @@ -6,7 +6,4 @@ import "regexp" const RestrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]` // RestrictedNamePattern is a regular expression to validate names against the collection of restricted characters. -var RestrictedNamePattern = regexp.MustCompile(`^/?` + RestrictedNameChars + `+$`) - -// RestrictedVolumeNamePattern is a regular expression to validate volume names against the collection of restricted characters. -var RestrictedVolumeNamePattern = regexp.MustCompile(`^` + RestrictedNameChars + `+$`) +var RestrictedNamePattern = regexp.MustCompile(`^` + RestrictedNameChars + `+$`) diff --git a/volume/local/local.go b/volume/local/local.go index 18ddca54d5705ee4028b963a2fdfe684886ee229..62c45e69eaafb7e90535ad81baf84c4dd55db0aa 100644 --- a/volume/local/local.go +++ b/volume/local/local.go @@ -36,7 +36,7 @@ var ( // volumeNameRegex ensures the name assigned for the volume is valid. // This name is used to create the bind directory, so we need to avoid characters that // would make the path to escape the root directory. - volumeNameRegex = utils.RestrictedVolumeNamePattern + volumeNameRegex = utils.RestrictedNamePattern ) type validationError struct {