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

validate the name of named volume

Signed-off-by: xlgao-zju <xlgao@zju.edu.cn>
This commit is contained in:
xlgao-zju 2015-09-29 17:00:08 +08:00 committed by David Calavera
parent ad861876e8
commit 609961ddcc
3 changed files with 19 additions and 0 deletions

View file

@ -24,6 +24,10 @@ func TestParseBindMount(t *testing.T) {
{"name:/tmp:ro", "local", "/tmp", "", "name", "local", false, false},
{"local/name:/tmp:rw", "", "/tmp", "", "local/name", "local", true, false},
{"/tmp:tmp", "", "", "", "", "", true, true},
{"./name:/tmp", "", "", "", "", "", true, true},
{"../name:/tmp", "", "", "", "", "", true, true},
{"./:/tmp", "", "", "", "", "", true, true},
{"../:/tmp", "", "", "", "", "", true, true},
}
for _, c := range cases {

View file

@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
@ -102,6 +103,12 @@ func parseBindMount(spec, volumeDriver string) (*mountPoint, error) {
}
if len(source) == 0 {
//validate the name of named volume
nameRegex := regexp.MustCompile(`(^.+[^0-9A-Za-z_]+$)|(/)`)
if nameRegex.MatchString(name) {
return nil, derr.ErrorCodeVolumeName.WithArgs(name)
}
bind.Driver = volumeDriver
if len(bind.Driver) == 0 {
bind.Driver = volume.DefaultDriverName

View file

@ -385,6 +385,14 @@ var (
HTTPStatusCode: http.StatusInternalServerError,
})
// ErrorCodeVolumeName is generated when the name of named volume isn't valid.
ErrorCodeVolumeName = errcode.Register(errGroup, errcode.ErrorDescriptor{
Value: "VOLUMENAME",
Message: "%s looks like a relative path, but it's taken as a name. And it is not a valid name.",
Description: "The name of named volume is invalid",
HTTPStatusCode: http.StatusInternalServerError,
})
// ErrorCodeVolumeFromBlank is generated when path to a volume is blank.
ErrorCodeVolumeFromBlank = errcode.Register(errGroup, errcode.ErrorDescriptor{
Value: "VOLUMEFROMBLANK",