summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-09-22 19:38:47 +0200
committerJakob Unterwurzacher2018-09-22 19:38:47 +0200
commit737a2f2012baf3f11056e08232c8d34dc353e2d8 (patch)
tree802f09a497aaf7cba10891dfacccffc4106a7da5 /internal
parent9e6ee47bc97ec78807d1f7ea7d8e0c9ff6ed31fe (diff)
syscallcompat: untangle Openat flag check
Check for O_NWFOLLOW and O_EXCL separately to make the logic clearer.
Diffstat (limited to 'internal')
-rw-r--r--internal/syscallcompat/sys_linux.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/internal/syscallcompat/sys_linux.go b/internal/syscallcompat/sys_linux.go
index 08483fd..6b75957 100644
--- a/internal/syscallcompat/sys_linux.go
+++ b/internal/syscallcompat/sys_linux.go
@@ -58,10 +58,18 @@ func Fallocate(fd int, mode uint32, off int64, len int64) (err error) {
// Openat wraps the Openat syscall.
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 && flags&syscall.O_EXCL != 0) && flags&syscall.O_NOFOLLOW == 0 {
- tlog.Warn.Printf("Openat: adding missing O_NOFOLLOW flag")
- flags |= syscall.O_NOFOLLOW
+ if flags&syscall.O_CREAT != 0 {
+ // O_CREAT should be used with O_EXCL. O_NOFOLLOW has no effect with O_EXCL.
+ if flags&syscall.O_EXCL == 0 {
+ 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)
}