public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug glob/25659] New: glob("/foo/*/") may also match regular & other kind of files, not just directories
@ 2020-03-12 7:45 spagoveanu at gmail dot com
2021-03-13 8:52 ` [Bug glob/25659] " stephane+sourceware at chazelas dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: spagoveanu at gmail dot com @ 2020-03-12 7:45 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=25659
Bug ID: 25659
Summary: glob("/foo/*/") may also match regular & other kind of
files, not just directories
Product: glibc
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: glob
Assignee: unassigned at sourceware dot org
Reporter: spagoveanu at gmail dot com
Target Milestone: ---
On Linux, glob(3) assumes that a regular file cannot have d_type == DT_UNKNOWN,
irrespective of filesystem support or whether the GLOB_ALTDIRFUNC feature was
used.
This results in a pattern like "/foo/*/" also matching non-directories, which
is contrary to what the standard requires ("The <slash> character in a pathname
shall be explicitly matched by using one or more <slash> characters in the
pattern"). At least on Linux, you CANNOT refer to a regular file as
"/path/to/file/".
See the simple testcase below, using a minix filesystem, which does not support
d_type.
You can also check these, about a (fixed) bug in GNU make, caused by its use of
GLOB_ALTDIRFUNC:
https://www.mail-archive.com/bug-make@gnu.org/msg11073.html
https://lists.gnu.org/archive/html/bug-make/2018-06/msg00009.html
Once upon a time I had started writing a patch, but I gave up as I had to
rewrite the whole logic of glob_in_dir(). FWIW, the glibc documentation claims
the GLOB_ONLYDIR is only a "hint", but the implementation itself is assuming
more than that.
--------------x----------------
# cat >glob.c <<'EOT'; cc -Wall -O2 glob.c -o glob
#include <stdio.h>
#include <glob.h>
int main(int ac, char **av){
int i, j;
for(i = 1; i < ac; i++){
glob_t g = {};
if(glob(av[i], 0, 0, &g) == 0)
for(j = 0; j < g.gl_pathc; j++)
printf("%s\n", g.gl_pathv[j]);
}
}
EOT
# truncate -s1G minix.img; mkfs.minix minix.img
...
# mkdir -p dir; mount minix.img dir
# touch dir/file
# ./glob 'dir/*/'
dir/file
--------------x----------------
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug glob/25659] glob("/foo/*/") may also match regular & other kind of files, not just directories
2020-03-12 7:45 [Bug glob/25659] New: glob("/foo/*/") may also match regular & other kind of files, not just directories spagoveanu at gmail dot com
@ 2021-03-13 8:52 ` stephane+sourceware at chazelas dot org
2021-03-13 9:16 ` gadelat at gmail dot com
2023-02-27 15:35 ` schwab@linux-m68k.org
2 siblings, 0 replies; 4+ messages in thread
From: stephane+sourceware at chazelas dot org @ 2021-03-13 8:52 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=25659
Stephane Chazelas <stephane+sourceware at chazelas dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |stephane+sourceware@chazela
| |s.org
--- Comment #1 from Stephane Chazelas <stephane+sourceware at chazelas dot org> ---
Note that it was reported at
https://unix.stackexchange.com/questions/638955/what-could-be-a-cause-for-getdents-returning-different-results-on-2-systems,
there about a "prl_fs" filesystem (likely related to some Parallel
virtualisation software).
I can reproduce it with glibc 2.33, and also with broken symlinks:
$ mkdir -p testdir/dir
$ ln -s /no/such/file testdir/broken
$ ./glob 'testdir/*/'
testdir/broken
testdir/dir/
Note that while the issue can be reproduced with ./*/ or b*/, I can't reproduce
it with */
$ cd testdir
$ ../glob './*/'
./broken
./dir/
$ ../glob 'b*/'
broken
$ ../glob '*/'
dir/
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug glob/25659] glob("/foo/*/") may also match regular & other kind of files, not just directories
2020-03-12 7:45 [Bug glob/25659] New: glob("/foo/*/") may also match regular & other kind of files, not just directories spagoveanu at gmail dot com
2021-03-13 8:52 ` [Bug glob/25659] " stephane+sourceware at chazelas dot org
@ 2021-03-13 9:16 ` gadelat at gmail dot com
2023-02-27 15:35 ` schwab@linux-m68k.org
2 siblings, 0 replies; 4+ messages in thread
From: gadelat at gmail dot com @ 2021-03-13 9:16 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=25659
Gabriel Ostrolucký <gadelat at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gadelat at gmail dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug glob/25659] glob("/foo/*/") may also match regular & other kind of files, not just directories
2020-03-12 7:45 [Bug glob/25659] New: glob("/foo/*/") may also match regular & other kind of files, not just directories spagoveanu at gmail dot com
2021-03-13 8:52 ` [Bug glob/25659] " stephane+sourceware at chazelas dot org
2021-03-13 9:16 ` gadelat at gmail dot com
@ 2023-02-27 15:35 ` schwab@linux-m68k.org
2 siblings, 0 replies; 4+ messages in thread
From: schwab@linux-m68k.org @ 2023-02-27 15:35 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=25659
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |2.36
Resolution|--- |FIXED
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> ---
Fixed in 2.36 by commit 7c477b57a3.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-27 15:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 7:45 [Bug glob/25659] New: glob("/foo/*/") may also match regular & other kind of files, not just directories spagoveanu at gmail dot com
2021-03-13 8:52 ` [Bug glob/25659] " stephane+sourceware at chazelas dot org
2021-03-13 9:16 ` gadelat at gmail dot com
2023-02-27 15:35 ` schwab@linux-m68k.org
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 read-only IMAP folder(s) and NNTP newsgroup(s).