mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jorge Almeida <jjalmeida@gmail.com>
To: musl@lists.openwall.com
Subject: fdopendir (BUG?)
Date: Mon, 28 Jan 2019 12:37:30 +0000	[thread overview]
Message-ID: <CAKpSnpJsgQuwOEiQ4xzMhboyFUoCq2uXQq_9Mo6MT8JusX5DJA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

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)

Am I  missing something? (Complete test program in attachement, so
that Gmail doesn't crap it.)

Thanks,

Jorge Almeida

[-- Attachment #2: test.c --]
[-- Type: text/x-csrc, Size: 792 bytes --]

#define _POSIX_C_SOURCE 200809L
//#define _GNU_SOURCE
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>

/* "somedir" should be an existing subdirectory of the current directory */

int main(int argc, char* argv[]){
		int fd=open("somedir", O_RDONLY|O_PATH|O_DIRECTORY);
//		int fd=open("somedir", O_RDONLY|O_DIRECTORY);
		if(fd == -1){
				fprintf(stderr, "open: %d\n", errno);
				exit(1);
		}
		DIR* dir=fdopendir(fd);
//		DIR* dir=opendir("somedir");
		if(dir == NULL){
				fprintf(stderr, "fdopendir: %d\n", errno);
				exit(1);
		}
		struct dirent* de;
		errno=0;
		de=readdir(dir);
		if(de == NULL && errno){
				fprintf(stderr, "readdir: %d\n", errno);
				exit(1);
		}
}

             reply	other threads:[~2019-01-28 12:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-28 12:37 Jorge Almeida [this message]
2019-01-28 16:16 ` Rich Felker
2019-01-28 18:53 ` Adhemerval Zanella
2019-01-28 19:42   ` Jorge Almeida
2019-01-28 20:30     ` Adhemerval Zanella
2019-01-28 21:33       ` Jorge Almeida
2019-01-29  1:50         ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKpSnpJsgQuwOEiQ4xzMhboyFUoCq2uXQq_9Mo6MT8JusX5DJA@mail.gmail.com \
    --to=jjalmeida@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).