syscallcompat: untangle Openat flag check
Check for O_NWFOLLOW and O_EXCL separately to make the logic clearer.
This commit is contained in:
parent
9e6ee47bc9
commit
737a2f2012
@ -58,10 +58,18 @@ func Fallocate(fd int, mode uint32, off int64, len int64) (err error) {
|
|||||||
|
|
||||||
// Openat wraps the Openat syscall.
|
// Openat wraps the Openat syscall.
|
||||||
func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
|
func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
|
||||||
// Why would we ever want to call this without O_NOFOLLOW and O_EXCL?
|
if flags&syscall.O_CREAT != 0 {
|
||||||
if !(flags&syscall.O_CREAT != 0 && flags&syscall.O_EXCL != 0) && flags&syscall.O_NOFOLLOW == 0 {
|
// O_CREAT should be used with O_EXCL. O_NOFOLLOW has no effect with O_EXCL.
|
||||||
tlog.Warn.Printf("Openat: adding missing O_NOFOLLOW flag")
|
if flags&syscall.O_EXCL == 0 {
|
||||||
flags |= syscall.O_NOFOLLOW
|
tlog.Warn.Printf("Openat: O_CREAT without O_EXCL: flags = %#x", flags)
|
||||||
|
flags |= syscall.O_EXCL
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If O_CREAT is not used, we should use O_NOFOLLOW
|
||||||
|
if flags&syscall.O_NOFOLLOW == 0 {
|
||||||
|
tlog.Warn.Printf("Openat: O_NOFOLLOW missing: flags = %#x", flags)
|
||||||
|
flags |= syscall.O_NOFOLLOW
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return syscall.Openat(dirfd, path, flags, mode)
|
return syscall.Openat(dirfd, path, flags, mode)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user