From 9ec9d0c49cfbdc9ceba10d7534b77e527c0a3cdc Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 8 Sep 2018 17:41:17 +0200 Subject: 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. --- internal/syscallcompat/open_nofollow_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'internal/syscallcompat/open_nofollow_test.go') 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 { -- cgit v1.2.3