Sfoglia il codice sorgente

Merge pull request #15846 from ZJU-SEL/11646-fix-path-validations

fix 11646 to check volume path in server side
Tibor Vass 9 anni fa
parent
commit
057f53f503

+ 1 - 0
daemon/volumes_linux_unit_test.go

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

+ 1 - 1
daemon/volumes_unit_test.go

@@ -2,7 +2,7 @@ package daemon
 
 
 import "testing"
 import "testing"
 
 
-func TestParseVolumeFrom(t *testing.T) {
+func TestParseVolumesFrom(t *testing.T) {
 	cases := []struct {
 	cases := []struct {
 		spec    string
 		spec    string
 		expID   string
 		expID   string

+ 5 - 0
daemon/volumes_unix.go

@@ -81,6 +81,11 @@ func parseBindMount(spec string, mountLabel string, config *runconfig.Config) (*
 		return nil, fmt.Errorf("Invalid volume specification: %s", spec)
 		return nil, fmt.Errorf("Invalid volume specification: %s", spec)
 	}
 	}
 
 
+	//validate the volumes destination path
+	if !filepath.IsAbs(bind.Destination) {
+		return nil, fmt.Errorf("Invalid volume destination path: %s mount path must be absolute.", bind.Destination)
+	}
+
 	name, source, err := parseVolumeSource(arr[0])
 	name, source, err := parseVolumeSource(arr[0])
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err