From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 06AC638582BC; Tue, 8 Aug 2023 15:52:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06AC638582BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1691509969; bh=0ioA5BxvNO3kLIpICf5/QzC63rhk5z/dod2fzNUsYx8=; h=From:To:Subject:Date:From; b=OEzsAmr2VVszh0NAyyIbCTWSTi+rhZdluWRvJMb5kDcmV0G/RwMJPu6Fsfqbumc76 m+FKZBTwwdA0s3+zrjapEhXZywOOZaZFiYquPLAL4eh5cTHJqq7W2JoT+pRrjgohSw FEzrpFe66HCAvpjo6auXbBNoYyG3A/UL5HEBg588= From: "markgaleck at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug libc/30737] New: fdopendir() is not robust - returns bogus DIR* instead of flagging an error Date: Tue, 08 Aug 2023 15:52:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: 2.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: markgaleck at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30737 Bug ID: 30737 Summary: fdopendir() is not robust - returns bogus DIR* instead of flagging an error Product: glibc Version: 2.35 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libc Assignee: unassigned at sourceware dot org Reporter: markgaleck at gmail dot com CC: drepper.fsp at gmail dot com Target Milestone: --- First, dislclaimer: I checked this issue is present on the latest Ubuntu distribution, which has glibc version 2.35, not the latest stable 2.38. I = was able to build 2.38 locally, but I am not able to force Ubuntu to accept it = for linking to the sample program, or to upgrade the installed glibc 2.35 to 2.= 38.=20 If you know how to test the sample program with 2.38, please let me know, a= nd I will do so and I will remove this report if it does not reproduce with glibc 2.38. --------------------------- Here is the SSCCE=20 'foobar.c' (which I obtained by necessary modifications to the sample code in man7 ent= ry for fdopendir() ) : #define _GNU_SOURCE #include #include #include #include #include int main(int argc, char* argv[]) { DIR* d; struct dirent* dp; int dfd; if ((d =3D fdopendir(open("./dir", O_RDONLY | O_PATH | O_DIRECTORY))) = =3D=3D NULL) { fprintf(stderr, "Cannot open directory\n"); exit(1); } while ((dp =3D readdir(d)) !=3D NULL) { if (!strcmp(dp->d_name, ".")) continue; if (!strcmp(dp->d_name, "..")) continue; printf("d_name %s\n", dp->d_name); } return 0; } ------------------------- Here is a script to show the problem: $ mkdir dir $ touch dir/file $ gcc -lc foobar.c $ ./a.out $ When called on a descriptor opened with O_PATH , fdopendir() succeeds happi= ly, but then, readdir() reports nothing! So the DIR* returned from fdopendir() is useless, but fdopendir() returns i= t, instead of NULL and setting errno to EBADF , as it should INHO If I remove | O_PATH from the above sample code, I get the expected result: $gcc -lc foobar.c $ ./a.out d_name file --=20 You are receiving this mail because: You are on the CC list for the bug.=