From: Bruno Haible <bruno@clisp.org>
Date: Sat, 7 Mar 2020 17:35:25 +0000 (+0100)
Subject: openat: Fix theoretically possible issue on GNU/Hurd.
X-Git-Tag: v1.0~4195
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a99ca2e041127e0c0d6c14273097c86879a6ebe3;p=gnulib.git

openat: Fix theoretically possible issue on GNU/Hurd.

Reported by Dan Gohman <sunfish@mozilla.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-03/msg00000.html>.

* lib/openat.c (rpl_openat): When testing whether flags contains O_RDWR,
ignore the bits that are also set in O_RDONLY.
---

diff --git a/ChangeLog b/ChangeLog
index 067e41956f..8414234c0e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-03-07  Bruno Haible  <bruno@clisp.org>
+
+	openat: Fix theoretically possible issue on GNU/Hurd.
+	Reported by Dan Gohman <sunfish@mozilla.com> in
+	<https://lists.gnu.org/archive/html/bug-gnulib/2020-03/msg00000.html>.
+	* lib/openat.c (rpl_openat): When testing whether flags contains O_RDWR,
+	ignore the bits that are also set in O_RDONLY.
+
 2020-02-24  Bruno Haible  <bruno@clisp.org>
 
 	getloadavg: Don't use /usr/local when cross-compiling on AIX.
diff --git a/lib/openat.c b/lib/openat.c
index d2c84e8f80..7d67dc4cad 100644
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -100,7 +100,7 @@ rpl_openat (int dfd, char const *filename, int flags, ...)
          directories,
        - if O_WRONLY or O_RDWR is specified, open() must fail because the
          file does not contain a '.' directory.  */
-  if (flags & (O_CREAT | O_WRONLY | O_RDWR))
+  if (flags & (O_CREAT | O_WRONLY | (O_RDWR & ~O_RDONLY)))
     {
       size_t len = strlen (filename);
       if (len > 0 && filename[len - 1] == '/')