Paul Eggert
2017-08-31 22:11:39 UTC
Thanks for working to clear up this longstanding problem in glibc glob.
Here are the issues I found with the proposed patch:
* glob_in_dir calls gl_stat, which is a typo; it should call gl_lstat.
* The GLOB_MARK checks should use stat not lstat, since symlinks to
directories should be marked.
* For GLOB_TILDE and GLOB_TILDE_CHECK, the revised code still tests for
existence of the home directory as a directory. Other glob
implementations merely expand the ~ or ~foo and treat the result as a
literal string, and glibc should be consistent here. This is simpler
and avoids a stat call.
* __lstat64 needs to be defined in the !_LIBC case too.
* While looking into this I noticed that glob ignores directory entries
with d_ino == 0. Although currently GNU/Linux cannot return such
entries, POSIX allows d_ino == 0 so this assumption is not portable, and
this bug is in the neighborhood so we might as well fix it in a
separated patch (which simplifies the code).
* commit message says "remove tst-glob3" but the patch actually removes
bug-glob1-ARGS.
I fixed these problems (except for the last one) while merging the patch
into Gnulib, and this resulted in the attached patches which I installed
into Gnulib master. I'll CC: this to bug-gnulib accordingly. Please
consider merging the glibc-relevant parts of these patches back into
glibc, for your next iteration of this glibc proposal. As always, the
goal is for glob.c and related files to be identical in glibc and Gnulib.
Here are the issues I found with the proposed patch:
* glob_in_dir calls gl_stat, which is a typo; it should call gl_lstat.
* The GLOB_MARK checks should use stat not lstat, since symlinks to
directories should be marked.
* For GLOB_TILDE and GLOB_TILDE_CHECK, the revised code still tests for
existence of the home directory as a directory. Other glob
implementations merely expand the ~ or ~foo and treat the result as a
literal string, and glibc should be consistent here. This is simpler
and avoids a stat call.
* __lstat64 needs to be defined in the !_LIBC case too.
* While looking into this I noticed that glob ignores directory entries
with d_ino == 0. Although currently GNU/Linux cannot return such
entries, POSIX allows d_ino == 0 so this assumption is not portable, and
this bug is in the neighborhood so we might as well fix it in a
separated patch (which simplifies the code).
* commit message says "remove tst-glob3" but the patch actually removes
bug-glob1-ARGS.
I fixed these problems (except for the last one) while merging the patch
into Gnulib, and this resulted in the attached patches which I installed
into Gnulib master. I'll CC: this to bug-gnulib accordingly. Please
consider merging the glibc-relevant parts of these patches back into
glibc, for your next iteration of this glibc proposal. As always, the
goal is for glob.c and related files to be identical in glibc and Gnulib.