syscallcompat: Use O_PATH to open base directory.

Also remove some unnecessary flags: When O_PATH is specified in flags, flag
bits other than O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW are ignored.
This commit is contained in:
Sebastian Lackner 2019-01-03 17:48:54 +01:00 committed by rfjakob
parent d86f9914ac
commit 927b3ce4cf
1 changed files with 2 additions and 3 deletions

View File

@ -23,8 +23,7 @@ func OpenDirNofollow(baseDir string, relPath string) (fd int, err error) {
return -1, syscall.EINVAL
}
// Open the base dir (following symlinks)
// TODO: should this use syscallcompat.O_PATH?
dirfd, err := syscall.Open(baseDir, syscall.O_RDONLY|syscall.O_DIRECTORY, 0)
dirfd, err := syscall.Open(baseDir, syscall.O_DIRECTORY|O_PATH, 0)
if err != nil {
return -1, err
}
@ -37,7 +36,7 @@ func OpenDirNofollow(baseDir string, relPath string) (fd int, err error) {
// Walk the directory tree
var dirfd2 int
for _, name := range parts {
dirfd2, err = Openat(dirfd, name, syscall.O_RDONLY|syscall.O_NOFOLLOW|syscall.O_DIRECTORY|O_PATH, 0)
dirfd2, err = Openat(dirfd, name, syscall.O_NOFOLLOW|syscall.O_DIRECTORY|O_PATH, 0)
syscall.Close(dirfd)
if err != nil {
return -1, err