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:
parent
ad861876e8
commit
609961ddcc
3 changed files with 19 additions and 0 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Reference in a new issue