From 74a67d01a5e523a6b865eeb2ae2abf6a91935c8c Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 22 Sep 2009 12:13:53 +0000 Subject: [PATCH] Make *at functions more like Linux. * syscalls.cc (faccessat): Fix typo, reject bad flags. (fchmodat, fchownat, fstatat, utimensat, linkat, unlinkat): Reject bad flags. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/syscalls.cc | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index ad149c8c5..9752abe5e 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2009-09-22 Eric Blake + + * syscalls.cc (faccessat): Fix typo, reject bad flags. + (fchmodat, fchownat, fstatat, utimensat, linkat, unlinkat): Reject + bad flags. + 2009-09-22 Corinna Vinschen * strfuncs.cc (sys_cp_mbstowcs): Reset shift state after handling diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 02a49b852..542a122d7 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -3851,7 +3851,8 @@ faccessat (int dirfd, const char *pathname, int mode, int flags) char *path = tp.c_get (); if (!gen_full_path_at (path, dirfd, pathname)) { - if (flags & ~(F_OK|R_OK|W_OK|X_OK)) + if ((mode & ~(F_OK|R_OK|W_OK|X_OK)) + || (flags & ~(AT_SYMLINK_NOFOLLOW|AT_EACCESS))) set_errno (EINVAL); else { @@ -3877,6 +3878,11 @@ fchmodat (int dirfd, const char *pathname, mode_t mode, int flags) myfault efault; if (efault.faulted (EFAULT)) return -1; + if (flags & ~AT_SYMLINK_NOFOLLOW) + { + set_errno (EINVAL); + return -1; + } char *path = tp.c_get (); if (gen_full_path_at (path, dirfd, pathname)) return -1; @@ -3891,6 +3897,11 @@ fchownat (int dirfd, const char *pathname, __uid32_t uid, __gid32_t gid, myfault efault; if (efault.faulted (EFAULT)) return -1; + if (flags & ~AT_SYMLINK_NOFOLLOW) + { + set_errno (EINVAL); + return -1; + } char *path = tp.c_get (); if (gen_full_path_at (path, dirfd, pathname)) return -1; @@ -3905,6 +3916,11 @@ fstatat (int dirfd, const char *pathname, struct __stat64 *st, int flags) myfault efault; if (efault.faulted (EFAULT)) return -1; + if (flags & ~AT_SYMLINK_NOFOLLOW) + { + set_errno (EINVAL); + return -1; + } char *path = tp.c_get (); if (gen_full_path_at (path, dirfd, pathname)) return -1; @@ -3922,6 +3938,11 @@ utimensat (int dirfd, const char *pathname, const struct timespec *times, if (efault.faulted (EFAULT)) return -1; char *path = tp.c_get (); + if (flags & ~AT_SYMLINK_NOFOLLOW) + { + set_errno (EINVAL); + return -1; + } if (gen_full_path_at (path, dirfd, pathname)) return -1; path_conv win32 (path, PC_POSIX | ((flags & AT_SYMLINK_NOFOLLOW) @@ -3952,6 +3973,11 @@ linkat (int olddirfd, const char *oldpathname, myfault efault; if (efault.faulted (EFAULT)) return -1; + if (flags & ~AT_SYMLINK_FOLLOW) + { + set_errno (EINVAL); + return -1; + } char *oldpath = tp.c_get (); if (gen_full_path_at (oldpath, olddirfd, oldpathname)) return -1; @@ -4060,6 +4086,11 @@ unlinkat (int dirfd, const char *pathname, int flags) myfault efault; if (efault.faulted (EFAULT)) return -1; + if (flags & ~AT_REMOVEDIR) + { + set_errno (EINVAL); + return -1; + } char *path = tp.c_get (); if (gen_full_path_at (path, dirfd, pathname)) return -1;