From da4c548bbb8c634c179d7c33f54fea651d1b3619 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 27 Dec 2005 07:59:00 +0000 Subject: [PATCH] (restricted_chown): Don't try O_WRONLY unless O_RDONLY failed wth EACCES. --- src/chown-core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/chown-core.c b/src/chown-core.c index 562b175c39..e691023cc1 100644 --- a/src/chown-core.c +++ b/src/chown-core.c @@ -191,15 +191,13 @@ restricted_chown (char const *file, { enum RCH_status status = RC_ok; struct stat st; - int o_flags = (O_NONBLOCK | O_NOCTTY); + int open_flags = O_NONBLOCK | O_NOCTTY; - int fd = open (file, O_RDONLY | o_flags); - if (fd < 0) - { - fd = open (file, O_WRONLY | o_flags); - if (fd < 0) - return RC_error; - } + int fd = open (file, O_RDONLY | open_flags); + if (! (0 <= fd + || (errno == EACCES + && 0 <= (fd = open (file, O_WRONLY | open_flags))))) + return RC_error; if (fstat (fd, &st) != 0) { -- 2.47.3