From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13671 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: fdopendir (BUG?) Date: Mon, 28 Jan 2019 11:16:13 -0500 Message-ID: <20190128161613.GD23599@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="158053"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13687-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jan 28 17:16:28 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1go9aG-000f0h-3q for gllmg-musl@m.gmane.org; Mon, 28 Jan 2019 17:16:28 +0100 Original-Received: (qmail 3854 invoked by uid 550); 28 Jan 2019 16:16:25 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 3830 invoked from network); 28 Jan 2019 16:16:25 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13671 Archived-At: On Mon, Jan 28, 2019 at 12:37:30PM +0000, Jorge Almeida wrote: > Calling fdopendir with a file descriptor obtained with O_PATH yields a > bad directory stream descriptor (as it should, if I understood > correctly the documentation of open() re O_PATH). However, the call > doesn't fail (it should fail with EBADF). A subsequent call to readdir > (3) detects the error. > > (the problem also occurs with glibc, besides the fact that glibc > requires also _GNU_SOURCE to compile, contradicting the linux man > page) Indeed, POSIX says "shall fail" if it's not a fd open for reading, so I think we need to detect this somehow. One obvious way, but it would require slightly invasive changes I think, is pre-buffering the first getdents at open time. Easier but slightly more expensive is doing a fcntl to get the file mode and rejecting O_PATH explicitly. Rich