[PATCH] posix: if glob has a trailing slash match directories only.

Paul Eggert eggert@cs.ucla.edu
Wed Nov 29 06:35:00 GMT 2017


Dmitry Goncharov wrote:

> Author: Ulrich Drepper<drepper@redhat.com>
> Date:   Fri Oct 31 22:55:02 1997 +0000

Ah, so this is a longstanding bug in glob, and was not introduced by the recent 
merge from Gnulib. That's a relief.

> As long as your filesystem initializes d->d_type you won't see the issue.
> When d->d_type is DT_UNKNOWN then d may not be a directory.

Thanks for clarifying. Now that I understand it better, though, I still see a 
problem. As noted in the Glibc manual here:

https://www.gnu.org/software/libc/manual/html_node/More-Flags-for-Globbing.html#index-GLOB_005fONLYDIR

GLOB_ONLYDIR is merely an efficiency flag: it means "do not return entries that 
can easily be shown to be non-directories". Your patch would change the 
semantics of GLOB_ONLYDIR so that it means "return only entries that are known 
to be directories", which differs from the Glibc documentation.

The bug here is not in the implementation of GLOB_ONLYDIR; it is in the part of 
glob that calls itself recursively with GLOB_ONLYDIR, and which expects only 
directories (or symlinks to directories) to be matched.

This issue came up in September, here:

https://sourceware.org/ml/libc-alpha/2017-09/msg00888.html



More information about the Libc-alpha mailing list