From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id ACE171F619 for ; Sat, 7 Mar 2020 19:11:25 +0000 (UTC) Received: from localhost ([::1]:52002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAer6-000396-CE for normalperson@yhbt.net; Sat, 07 Mar 2020 14:11:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38300) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAer2-000390-0q for bug-gnulib@gnu.org; Sat, 07 Mar 2020 14:11:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAer0-0007xM-78 for bug-gnulib@gnu.org; Sat, 07 Mar 2020 14:11:19 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:44524) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jAeqz-0007tb-U6 for bug-gnulib@gnu.org; Sat, 07 Mar 2020 14:11:18 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 9D1101600C5; Sat, 7 Mar 2020 11:05:11 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id gEjP9nr0XbNa; Sat, 7 Mar 2020 11:05:10 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 143951600C6; Sat, 7 Mar 2020 11:05:10 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ym_3UdUQ1dSB; Sat, 7 Mar 2020 11:05:09 -0800 (PST) Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id CD64A1600C5; Sat, 7 Mar 2020 11:05:09 -0800 (PST) Subject: Re: openat wrapper assumes that O_RDONLY is disjoint from R_RDWR To: Dan Gohman , Bruno Haible References: <2134597.WplbXgMu3H@omega> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <3e35624d-7502-3341-c7f1-49320268dab9@cs.ucla.edu> Date: Sat, 7 Mar 2020 11:05:09 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------2213CE99698DD7E3261FCC7B" Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --------------2213CE99698DD7E3261FCC7B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 3/4/20 9:24 AM, Dan Gohman wrote: >> Would >> if (flags & ((O_CREAT | O_WRONLY | O_RDWR) & ~O_RDONLY)) >> be correct? >> > That would fix the problem for systems that define O_RDONLY as Hurd does, > while not breaking any known systems. > > It wouldn't be correct on a hypothetical system Thanks for mentioning this. We might as well fix the code for the hypothetical systems while we're at it, since we can use O_ACCMODE here. The issue also occurs in the 'open' wrapper. I installed the attached patch. --------------2213CE99698DD7E3261FCC7B Content-Type: text/x-patch; charset=UTF-8; name="0001-open-openat-port-to-O_RDWR-O_RDONLY-0.patch" Content-Disposition: attachment; filename="0001-open-openat-port-to-O_RDWR-O_RDONLY-0.patch" Content-Transfer-Encoding: quoted-printable >From 1d86584739a712597a6fe3a62ec412238f0f13f8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 7 Mar 2020 11:02:05 -0800 Subject: [PATCH] open, openat: port to (O_RDWR | O_RDONLY) !=3D 0 MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Potential portability problem reported by Dan Gohman in: https://lists.gnu.org/r/bug-gnulib/2020-03/msg00000.html * lib/open.c (open): * lib/openat.c (rpl_openat): Don=E2=80=99t assume O_RDONLY is disjoint from O_RDWR. --- ChangeLog | 9 +++++++++ lib/open.c | 4 +++- lib/openat.c | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0eddfee99..f6bd5180c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2020-03-07 Paul Eggert + + open, openat: port to (O_RDWR | O_RDONLY) !=3D 0 + Potential portability problem reported by Dan Gohman in: + https://lists.gnu.org/r/bug-gnulib/2020-03/msg00000.html + * lib/open.c (open): + * lib/openat.c (rpl_openat): + Don=E2=80=99t assume O_RDONLY is disjoint from O_RDWR. + 2020-03-07 Bruno Haible =20 findprog, relocatable-prog: Ignore directories during PATH search. diff --git a/lib/open.c b/lib/open.c index 487194f66..bb180fde2 100644 --- a/lib/open.c +++ b/lib/open.c @@ -110,7 +110,9 @@ open (const char *filename, int flags, ...) directories, - if O_WRONLY or O_RDWR is specified, open() must fail because th= e file does not contain a '.' directory. */ - if (flags & (O_CREAT | O_WRONLY | O_RDWR)) + if ((flags & O_CREAT) + || (flags & O_ACCMODE) =3D=3D O_RDWR + || (flags & O_ACCMODE) =3D=3D O_WRONLY) { size_t len =3D strlen (filename); if (len > 0 && filename[len - 1] =3D=3D '/') diff --git a/lib/openat.c b/lib/openat.c index 7d67dc4ca..fdbe83f43 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -100,7 +100,9 @@ rpl_openat (int dfd, char const *filename, int flags,= ...) directories, - if O_WRONLY or O_RDWR is specified, open() must fail because th= e file does not contain a '.' directory. */ - if (flags & (O_CREAT | O_WRONLY | (O_RDWR & ~O_RDONLY))) + if ((flags & O_CREAT) + || (flags & O_ACCMODE) =3D=3D O_RDWR + || (flags & O_ACCMODE) =3D=3D O_WRONLY) { size_t len =3D strlen (filename); if (len > 0 && filename[len - 1] =3D=3D '/') --=20 2.17.1 --------------2213CE99698DD7E3261FCC7B--