• Bug#976865: Fwd: Bug#974900: dash removes trailing slash from script ar

    From Herbert Xu@21:1/5 to Aurelien Jarno on Thu Dec 10 12:40:01 2020
    XPost: linux.debian.bugs.dist

    On Thu, Dec 10, 2020 at 08:58:37AM +0100, Aurelien Jarno wrote:

    That's the dash symptoms. glob(3) takes a pattern and just returns the
    paths matching the pattern, as they are named on the filesystem. That
    said, the option GLOB_MARK can return a trailing slash for all matched
    path that are a directory.

    Yes but it's really a bug in glob(3). It should really return
    a no-match for the case in question, rather than matching and then
    returning a filename without the slash.

    IOW the pattern "foo\/" should not match a regular file foo.

    Note that the problem doesn't occur for "foo/".

    Cheers,
    --
    Email: Herbert Xu <herbert@gondor.apana.org.au>
    Home Page: http://gondor.apana.org.au/~herbert/
    PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Aurelien Jarno@21:1/5 to Herbert Xu on Thu Dec 10 09:10:02 2020
    XPost: linux.debian.bugs.dist

    On 2020-12-10 13:56, Herbert Xu wrote:
    Aurelien Jarno <aurelien@aurel32.net> wrote:

    Can you please describe more precisely what is the problem with glob(3)?

    It's stripping trailing slashes from the pattern, even when the
    name in question is a regular file.

    https://patchwork.kernel.org/project/dash/patch/20201116025222.GA28742@gondor.apana.org.au/

    That's the dash symptoms. glob(3) takes a pattern and just returns the
    paths matching the pattern, as they are named on the filesystem. That
    said, the option GLOB_MARK can return a trailing slash for all matched
    path that are a directory.

    --
    Aurelien Jarno GPG: 4096R/1DDD8C9B aurelien@aurel32.net http://www.aurel32.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Herbert Xu@21:1/5 to Aurelien Jarno on Thu Dec 10 13:20:01 2020
    XPost: linux.debian.bugs.dist

    On Wed, Dec 09, 2020 at 01:27:17PM +0100, Aurelien Jarno wrote:

    Can you please describe more precisely what is the problem with glob(3)?

    Create a regular file called "foo", then call glob(3) with the
    pattern "foo\/". This returns a single match with the string
    "foo". This should return no match.

    If you change the pattern to "foo/", then it also matches but
    returns with the string "foo/" as expected.

    The only flag we pass to glob(3) is GLOB_NOMAGIC.

    Cheers,
    --
    Email: Herbert Xu <herbert@gondor.apana.org.au>
    Home Page: http://gondor.apana.org.au/~herbert/
    PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeff King@21:1/5 to Herbert Xu on Thu Dec 10 16:40:02 2020
    XPost: linux.debian.bugs.dist

    On Thu, Dec 10, 2020 at 10:35:08PM +1100, Herbert Xu wrote:

    Yes but it's really a bug in glob(3). It should really return
    a no-match for the case in question, rather than matching and then
    returning a filename without the slash.

    IOW the pattern "foo\/" should not match a regular file foo.

    Note that the problem doesn't occur for "foo/".

    It seems like it happens for "foo/", too. If I compile:

    -- >8 --
    #include <glob.h>
    #include <stdio.h>

    int main(int argc, const char **argv)
    {
    while (*++argv) {
    glob_t r;
    if (glob(*argv, 0, NULL, &r))
    perror(*argv);
    else {
    size_t i;
    for (i = 0; i < r.gl_pathc; i++)
    printf("%s -> %s\n", *argv, r.gl_pathv[i]);
    globfree(&r);
    }
    }
    return 0;
    }
    -- >8 --

    I get:

    $ rm -f foo bar
    $ touch foo
    $ ./a.out foo foo/ 'foo\/' bar bar/ 'bar\/'
    foo -> foo
    foo/ -> foo
    foo\/ -> foo
    bar: No such file or directory
    bar/: No such file or directory
    bar\/: No such file or directory

    -Peff

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Herbert Xu@21:1/5 to Aurelien Jarno on Thu Dec 10 04:20:01 2020
    XPost: linux.debian.bugs.dist

    Aurelien Jarno <aurelien@aurel32.net> wrote:

    Can you please describe more precisely what is the problem with glob(3)?

    It's stripping trailing slashes from the pattern, even when the
    name in question is a regular file.

    https://patchwork.kernel.org/project/dash/patch/20201116025222.GA28742@gondor.apana.org.au/

    Cheers,
    --
    Email: Herbert Xu <herbert@gondor.apana.org.au>
    Home Page: http://gondor.apana.org.au/~herbert/
    PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)