bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

openat wrapper assumes that O_RDONLY is disjoint from R_RDWR


From: Dan Gohman
Subject: openat wrapper assumes that O_RDONLY is disjoint from R_RDWR
Date: Tue, 3 Mar 2020 12:24:46 -0800

The following code in Gnulib's openat function:

http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/openat.c;h=d2c84e8f80489201be2a7198bb979fe4be6f9ecb;hb=HEAD#l103

tests for a file mode being writable with the following _expression_:

> if (flags & (O_CREAT | O_WRONLY | O_RDWR))

However, this can erroneously return true on systems where O_RDWR shares
bits with R_RDONLY. POSIX doesn't guarantee anything about the values of O_RDWR and O_RDONLY, and GNU Hurd is an example of a system where O_RDWR and O_RDONLY do share bits:

https://www.gnu.org/software/libc/manual/html_node/Access-Modes.html#Access-Modes

That said, the code in question is only used on platforms where `OPEN_TRAILING_SLASH_BUG` is defined, and I don't have any ready examples of relevant platforms with both `OPEN_TRAILING_SLASH_BUG` defined and with `O_RDWR` sharing bits with `O_RDONLY`. However, such a platform is a theoretical possibility.

Dan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]