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

Merge pull request #13639 from tonistiigi/fix-git-escape

Make sure git remote subdirs don't escape git root
This commit is contained in:
David Calavera 2015-06-01 13:04:39 -07:00
commit 64a7431663
2 changed files with 17 additions and 1 deletions

View file

@ -10,6 +10,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/docker/docker/pkg/symlink"
"github.com/docker/docker/pkg/urlutil" "github.com/docker/docker/pkg/urlutil"
) )
@ -69,7 +70,11 @@ func checkoutGit(fragment, root string) (string, error) {
} }
if len(refAndDir) > 1 && len(refAndDir[1]) != 0 { if len(refAndDir) > 1 && len(refAndDir[1]) != 0 {
newCtx := filepath.Join(root, refAndDir[1]) newCtx, err := symlink.FollowSymlinkInScope(filepath.Join(root, refAndDir[1]), root)
if err != nil {
return "", fmt.Errorf("Error setting git context, %q not within git root: %s", refAndDir[1], err)
}
fi, err := os.Stat(newCtx) fi, err := os.Stat(newCtx)
if err != nil { if err != nil {
return "", err return "", err

View file

@ -103,6 +103,14 @@ func TestCheckoutGit(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil {
t.Fatal(err)
}
if err = os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")); err != nil {
t.Fatal(err)
}
if _, err = gitWithinDir(gitDir, "add", "-A"); err != nil { if _, err = gitWithinDir(gitDir, "add", "-A"); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -147,6 +155,9 @@ func TestCheckoutGit(t *testing.T) {
{":Dockerfile", "", true}, // not a directory error {":Dockerfile", "", true}, // not a directory error
{"master:nosubdir", "", true}, {"master:nosubdir", "", true},
{"master:subdir", "FROM scratch\nEXPOSE 5000", false}, {"master:subdir", "FROM scratch\nEXPOSE 5000", false},
{"master:parentlink", "FROM scratch\nEXPOSE 5000", false},
{"master:absolutelink", "FROM scratch\nEXPOSE 5000", false},
{"master:../subdir", "", true},
{"test", "FROM scratch\nEXPOSE 3000", false}, {"test", "FROM scratch\nEXPOSE 3000", false},
{"test:", "FROM scratch\nEXPOSE 3000", false}, {"test:", "FROM scratch\nEXPOSE 3000", false},
{"test:subdir", "FROM busybox\nEXPOSE 5000", false}, {"test:subdir", "FROM busybox\nEXPOSE 5000", false},