Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 28 Jan 2019 11:16:13 -0500
From: Rich Felker <>
Subject: Re: fdopendir (BUG?)

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.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.