diff options
author | Jakob Unterwurzacher | 2018-09-08 17:41:17 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2018-09-08 17:41:17 +0200 |
commit | 9ec9d0c49cfbdc9ceba10d7534b77e527c0a3cdc (patch) | |
tree | a7beb635c6ac0d7580e95811d1803f9750c431aa /internal/syscallcompat/open_nofollow_test.go | |
parent | bc14f8dcb65740dac792b50f2582372762e782b8 (diff) |
syscallcompat: untangle OpenNofollow and rename to OpenDirNofollow
The function used to do two things:
1) Walk the directory tree in a manner safe from symlink attacks
2) Open the final component in the mode requested by the caller
This change drops (2), which was only used once, and lets the caller
handle it. This simplifies the function and makes it fit for reuse in
forward mode in openBackingPath(), and for using O_PATH on Linux.
Diffstat (limited to 'internal/syscallcompat/open_nofollow_test.go')
-rw-r--r-- | internal/syscallcompat/open_nofollow_test.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/syscallcompat/open_nofollow_test.go b/internal/syscallcompat/open_nofollow_test.go index 1f21557..1eeac3a 100644 --- a/internal/syscallcompat/open_nofollow_test.go +++ b/internal/syscallcompat/open_nofollow_test.go @@ -12,7 +12,11 @@ func TestOpenNofollow(t *testing.T) { t.Fatal(err) } // Create a file - fd, err := OpenNofollow(tmpDir, "d1/d2/d3/f1", syscall.O_RDWR|syscall.O_CREAT|syscall.O_EXCL, 0600) + dirfd, err := OpenDirNofollow(tmpDir, "d1/d2/d3") + if err != nil { + t.Fatal(err) + } + fd, err := Openat(dirfd, "f1", syscall.O_RDWR|syscall.O_CREAT|syscall.O_EXCL, 0600) if err != nil { t.Fatal(err) } @@ -27,7 +31,7 @@ func TestOpenNofollow(t *testing.T) { t.Fatal(err) } os.Symlink(tmpDir+"/d1.renamed", tmpDir+"/d1") - fd, err = OpenNofollow(tmpDir, "d1/d2/d3/f1", syscall.O_RDWR|syscall.O_CREAT, 0600) + fd, err = OpenDirNofollow(tmpDir, "d1/d2/d3") if err == nil { t.Fatalf("should have failed") } @@ -35,7 +39,7 @@ func TestOpenNofollow(t *testing.T) { t.Errorf("expected ELOOP or ENOTDIR, got %v", err) } // Check to see that the base dir can be opened as well - fd, err = OpenNofollow(tmpDir, "", syscall.O_RDONLY, 0) + fd, err = OpenDirNofollow(tmpDir, "") if err != nil { t.Errorf("cannot open base dir: %v", err) } else { |