From 64b6d99e35c19493233eda9cc274547b3addbaad Mon Sep 17 00:00:00 2001 From: lalyos Date: Thu, 15 May 2014 23:52:36 +0200 Subject: [PATCH] Adding test case for symlink causes infinit loop, reproduces: dotcloud#5370 normally symlinks are created as either ln -s /path/existing /path/new-name or cd /path && ln -s ./existing new-name but one can create it this way cd /path && ln -s existing new-name this drives FollowSymlinkInScope into infinite loop Docker-DCO-1.1-Signed-off-by: Lajos Papp (github: lalyos) --- symlink/fs_test.go | 13 +++++++++++++ symlink/testdata/fs/i | 1 + 2 files changed, 14 insertions(+) create mode 120000 symlink/testdata/fs/i diff --git a/symlink/fs_test.go b/symlink/fs_test.go index 1f12aa3..d85fd6d 100644 --- a/symlink/fs_test.go +++ b/symlink/fs_test.go @@ -28,6 +28,19 @@ func TestFollowSymLinkNormal(t *testing.T) { } } +func TestFollowSymLinkRelativePath(t *testing.T) { + link := "testdata/fs/i" + + rewrite, err := FollowSymlinkInScope(link, "testdata") + if err != nil { + t.Fatal(err) + } + + if expected := abs(t, "testdata/fs/a"); expected != rewrite { + t.Fatalf("Expected %s got %s", expected, rewrite) + } +} + func TestFollowSymLinkUnderLinkedDir(t *testing.T) { dir, err := ioutil.TempDir("", "docker-fs-test") if err != nil { diff --git a/symlink/testdata/fs/i b/symlink/testdata/fs/i new file mode 120000 index 0000000..2e65efe --- /dev/null +++ b/symlink/testdata/fs/i @@ -0,0 +1 @@ +a \ No newline at end of file