Bug 866 - glob should match dangling symlinks
Summary: glob should match dangling symlinks
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: glob (show other bugs)
Version: 2.3.5
: P2 normal
Target Milestone: 2.27
Assignee: Adhemerval Zanella
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-22 19:50 UTC by Steven Plite
Modified: 2017-09-08 14:38 UTC (History)
8 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build:
Last reconfirmed:
fweimer: security-


Attachments
fix globbing of dangling symlinks in sysdeps/generic/glob.c (834 bytes, patch)
2005-04-22 19:54 UTC, Steven Plite
Details | Diff
866-v2: updated patch that applies cleanly against master (788 bytes, patch)
2012-09-27 04:43 UTC, Tom Lee
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steven Plite 2005-04-22 19:50:20 UTC
The 1.53 revision to sysdeps/generic/glob.c added a check for dangling symlinks.
 While necessary for directory globs, it still seems desirable to match dangling
symlinks in filename globs, as bash and tcsh's built-in globbers do.  This
program demonstrates the problem:

% cat globtest.c
#include <stdio.h>
#include <glob.h>

main()
{
        int i;
        glob_t pglob;

        chdir("/tmp");
        symlink("/nope", "foo1");
        symlink("/usr", "foo2");
        glob("foo[12]", 0, 0, &pglob);
        for (i = 0; i < pglob.gl_pathc; i++)
                printf("pglob.gl_pathv[%d] = \"%s\"\n", i, pglob.gl_pathv[i]);
        unlink("foo1");
        unlink("foo2");
}
% gcc -o globtest globtest.c
% ./globtest
pglob.gl_pathv[0] = "foo2"


Same thing in bash (tcsh behaves identically):

bash-2.05b$ cd /tmp
bash-2.05b$ ln -s /nope foo1
bash-2.05b$ ln -s /usr foo2
bash-2.05b$ echo foo[12]
foo1 foo2
bash-2.05b$ rm foo1 foo2


I'm attaching a patch to glob.c that makes glob()'s behavior mimic bash and
tcsh's.  The resulting glob() still passes globtest.sh, so it seems correct.
Comment 1 Steven Plite 2005-04-22 19:54:37 UTC
Created attachment 461 [details]
fix globbing of dangling symlinks in sysdeps/generic/glob.c

Adding another argument to glob_in_dir() was the easiest route, but perhaps one
of its existing arguments could be (ab)used instead.
Comment 2 Ulrich Drepper 2005-09-27 05:54:41 UTC
This behavior is correct.  There won't be any change.
Comment 3 Panu Matilainen 2012-05-08 11:25:28 UTC
Any chance of reconsidering this?
Comment 4 joseph@codesourcery.com 2012-05-08 11:50:50 UTC
If you believe a bug was inappropriately closed, you need to reopen it, or 
open a new bug for the same issue, preferably with detailed references to 
the appropriate standards or other reasons you think the closure was 
inappropriate.  Comments on closed bugs don't make the bugs appear to 
anyone subsequently doing bug triage.
Comment 5 Rich Felker 2012-05-08 16:43:12 UTC
This seems like yet another unexplained/unreasonable bug closure by Drepper. Can we please get a serious review of it. I think the fact that glob() is behaving differently from bash, and the fact that one expects "rm *" to remove everything including dangling symlinks, speaks for itself; POSIX does not have any special language about symlinks in the specification for glob, so by default I think it requires them to be included in the results.
Comment 6 Tom Lee 2012-09-27 04:43:17 UTC
Created attachment 6655 [details]
866-v2: updated patch that applies cleanly against master

Here's an updated version of Steven's patch that applies cleanly against the current master branch in case anybody wants to play with it.

Seems to work well, but I'm new here -- not sure what the policy is wrt tests?
Comment 7 Michael Matz 2017-03-06 14:59:47 UTC
Just one more data point, we got a customer also being surprised by this
divergence from shell behaviour when all existing documentation suggests
that it should match.  So, to get all info in one place, the redhat report
was:

https://bugzilla.redhat.com/show_bug.cgi?id=126460

our (https://bugzilla.novell.com/show_bug.cgi?id=1026911) is unfortunately
inaccessible to the outside, but describes exactly this issue with essentially
the same testcases.
Comment 8 cvs-commit@gcc.gnu.org 2017-07-26 20:17:40 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, azanella/glob-fixes has been created
        at  80aed7ed5a919358c0bce9bfee97c4d8ac533d5e (commit)

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=80aed7ed5a919358c0bce9bfee97c4d8ac533d5e

commit 80aed7ed5a919358c0bce9bfee97c4d8ac533d5e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Jul 26 16:09:26 2017 -0300

    posix: Fix glob with GLOB_NOCHECK returning modified patterns (BZ#10246)
    
    Acconding to POSIX glob with GLOB_NOCHECK should return a list consisting
    of only of the input pattern in case of no match.  However GLIBC does not
    honor in case of '//<something'.  This is due internally this is handled
    and special case and prefix_array (responsable to prepend the directory
    name) does not know if the input already contains a slash or not since
    either '/<something>' or '//<something>' will be handle in same way.
    
    This patch fix it by using a empty directory name for the latter (since
    prefix_array already adds a slash as default for each entry).
    
    Checked on x86_64-linux-gnu.
    
    	[BZ #10246]
    	* posix/glob.c (glob): Handle pattern that do not match and
    	start with '/' correctly.
    	* posix/globtest.sh: New tests for NOCHECK.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c50dfe79df1b3a3fe3ba3bc1eba3c354a5d122a6

commit c50dfe79df1b3a3fe3ba3bc1eba3c354a5d122a6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Jul 26 11:39:49 2017 -0300

    posix: Use enum for __glob_pattern_type result
    
    This patch replaces the internal integer constant from
    __glob_pattern_type return with a proper enum.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob_internal.h (__glob_pat_types): New enumeration.
    	(__glob_pattern_type): Use __glob_pat_types.
    	* posix/glob_pattern_p.c (__glob_pattern_p): Likewise.
    	* posix/glob.c (glob): Likewise.
    	(glob_in_dir): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6e05025f557147feec2772f2e65a2f95baae0eee

commit 6e05025f557147feec2772f2e65a2f95baae0eee
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Jun 7 09:33:19 2017 -0300

    posix: More check for overflow allocation in glob
    
    This patch adds and replace the allocation overflow based using
    malloc internal functions check_add_wrapv_size_t and __libc_reallocarray.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob.c (glob_malloc_incr): New function.
    	(glob_malloc_incr2): Likewise.
    	(glob_realloc_incr): Likewise.
    	(glob): Use glob_{realloc,malloc}_incr{2}.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=89e7c2b0d336e51968484d187aa67b250bfbc7a2

commit 89e7c2b0d336e51968484d187aa67b250bfbc7a2
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 6 11:38:29 2017 -0300

    posix: Add common function to get home directory
    
    This patch adds a common function to get the full home directory
    from a user.  No functional changes expected.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob.c (get_home_directory): New function.
    	(glob): Use get_home_directory.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5f9db2076c77c55d6b81cf38ea2621e7f71f59c1

commit 5f9db2076c77c55d6b81cf38ea2621e7f71f59c1
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 6 10:57:33 2017 -0300

    posix: Use char_array for home_dir in glob
    
    This patch uses char_array for home directory discovery.  It simplifies
    the buffer management.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob.c (glob): Use char_array for home directory.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=44684cd21876bde13fc3bed741f887ebff173d69

commit 44684cd21876bde13fc3bed741f887ebff173d69
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jun 5 19:55:48 2017 -0300

    posix: Remove all alloca usage in glob
    
    With alloca usage removal from glob this patch wraps it up by removing
    all the alloca defines and macros usage.
    
    Checked on x86_64-linux-gnu.
    
    	posix/glob.c (glob_in_dir): Remove alloca_used argument.
    	(glob): Remove alloca_used.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3a5cee0bfadd7f3b6b1a273570c25daecba731c9

commit 3a5cee0bfadd7f3b6b1a273570c25daecba731c9
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jun 5 19:41:58 2017 -0300

    posix: Use dynarray for globname in glob
    
    This patch uses dynarray at glob internal glob_in_dir function to manage
    the various matched patterns.  It simplify and removes all the boilerplate
    buffer managements required.  It also removes the glob_use_alloca, since
    it is not used anymore.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob.c (glob_use_alloca): Remove.
    	(glob_in_dir): Use dynarray for globnames.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=923c67dea223b7d2f02cbd8ccf7c588aaf439ba6

commit 923c67dea223b7d2f02cbd8ccf7c588aaf439ba6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jun 5 17:20:01 2017 -0300

    posix: Remove alloca usage on glob dirname
    
    This patch replaces the alloca/malloc usage for dirname creation
    by the char_array struct.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob.c (glob_in_dir): Remove alloca usage for fullname.
    	* malloc/char_array-skeleton.c (char_array_init_str): Remove unused
    	attribute.
    	(char_array_append_str): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=34f6a6e813fbb9d15895008157a4c3fe9f6a19d8

commit 34f6a6e813fbb9d15895008157a4c3fe9f6a19d8
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jun 5 15:19:22 2017 -0300

    posix: Remove alloca usage for GLOB_BRACE on glob
    
    GNU GLOB_BRACE internal implementation constructs a new expression and
    calls glob recursively.  It then requires a possible large temporary
    buffer place the new pattern.
    
    This patch removes the alloca/malloc usage and replaces it with
    char_array.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob.c (glob): Remove alloca usage for onealt.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5389d55d0488f71d7dbcda40c24b78d33fd960ec

commit 5389d55d0488f71d7dbcda40c24b78d33fd960ec
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jun 5 12:31:21 2017 -0300

    posix: User LOGIN_NAME_MAX for all user name in glob
    
    This patch limits all user name obtained for GLOB_TILDE to max of
    LOGIN_NAME_MAX (256 on glibc) and remove all stack/malloc buffer
    handling boilerplate.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob.c (glob): Remove alloca usage on user_name for
    	GLOB_TILDE.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=08530e743120416c3efd23e61920afc16e3dc5d7

commit 08530e743120416c3efd23e61920afc16e3dc5d7
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jun 5 12:12:38 2017 -0300

    posix: Remove glob GET_LOGIN_NAME_MAX usage
    
    Current glob implementation allows non limited user name for home
    directory construction on GLOB_TILDE case.  To accomplish it glob
    either construct a name on stack if size are small enough (based
    on current alloca_used) value in heap otherwise.
    
    There is no actual login to resize the buffer in case of the resizing
    the buffer in case of ERANGE, so a static buffer using glibc default
    LOGIN_NAME_MAX is suffice.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/glob.c (LOGIN_NAME_MAX): Define if not defined.
    	(glob): Use static buffer for user_name on getlogin_r.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a192083bb599321a0d16ca31978d6be3f8f857ff

commit a192083bb599321a0d16ca31978d6be3f8f857ff
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Sun Jun 4 16:53:20 2017 -0300

    posix: Use char_array for internal glob dirname
    
    This is the first patch of the set to remove alloca usage on glob
    implementation.  Internal path to search for file might expand to a
    non static directory derived from pattern for some difference cases
    (GLOB_NOESCAPE, GNU GLOB_TILDE) and to allow a non-static dirname
    path glob uses a lot of boilerplate code to manage the buffer (which
    is either allocated using alloca or malloc depending both to size
    requested and the total alloca_used).
    
    The patch changes to use the char_array struct with the default size
    (256 bytes).  It simplifies all the allocation code by using char_array
    one and every internal buffer access is done using char_array provided
    functions.  No functional changes are expected.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/globc.c (glob): Use char_array for dirname.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7f028010854a13cecdbea14954ea97a94428bad7

commit 7f028010854a13cecdbea14954ea97a94428bad7
Author: Florian Weimer <fweimer@redhat.com>
Date:   Sat Jun 3 20:22:24 2017 -0300

    posix: Rewrite to use struct scratch_buffer instead of extend_alloca
    
    This patch removes a lot of boilerplate code to manager buffers for
    getpwnam_r.
    
    Checked on x86_64-linux-gnu.
    
    	[BZ #18023]
    	* posix/glob.c (glob): Use struct scratch_buffer instead of
    	extend_alloca.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=782c40918fa3d3a161e4fe3014ea23c2bd170872

commit 782c40918fa3d3a161e4fe3014ea23c2bd170872
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Jun 2 15:38:04 2017 -0300

    posix: Consolidate glob implementation
    
    This patch consolidates the glob implementation.  The main changes are:
    
      * Remove specific defines required for multiple compilation in same
        unit (GLOB_ONLY_P, NO_GLOB_PATTERN_P and GLOB_COMPAT_BUILD).  To allow
        using the same code to build compat version on Linux, extra units are
        used instead (oldglob.c).
    
      * Both globfree and GNU extension glob_pattern_p are now on their files.
        This simplifies the creation of compat symbol when required.
    
      * Also similar to glob/glob64, a new globfree64 is file is added with an
        empty implementatio as default.
    
      * On Linux all implementation now uses a default one with the exception
        of alpha (which requires a specific versioning) and s390-32 (which
        different than other 32 bits with support for v2.1 symbol does not
        add a compat symbol).
    
      * Move i386 olddirent.h header to Linux default directory, since it is
        the only header with this name and it is shared among different
        architectures (and used on compat glob symbol).
    
    Checked on x86_64-linux-gnu and i686-linux-gnu.
    
    	* posix/Makefile (routines): Add globfree, globfree64, and
    	glob_pattern_p.
    	* posix/glob.c: Remove GLOB_ONLY_P, GLOB_COMPAT_BUILD, and
    	NO_GLOB_PATTERN_P define usage.
    	(globfree): Move to its own file.
    	(__glob_pattern_type): Likewise.
    	(__glob_pattern_p): Likewise.
    	* posix/glob_internal.h: New file.
    	* posix/glob_pattern_p.c: Likewise.
    	* posix/globfree.c: Likewise.
    	* posix/globfree64.c: Likewise.
    	* sysdeps/gnu/glob64.c: Remove file.
    	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add oldglob.
    	* sysdeps/unix/sysv/linux/alpha/Makefile [$(subdir) = posix]
    	(sysdep_routines): Remove rule.
    	* sysdeps/unix/sysv/linux/alpha/glob.c: Remove file.
    	* sysdeps/unix/sysv/linux/arm/glob64.c: Likewise.
    	* sysdeps/wordsize-64/glob.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips64/n64/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/powerpc32/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/wordsize-64/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/x32/glob.c: Likewise.
    	* sysdeps/wordsize-64/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/alpha/glob64.c: New file.
    	* sysdeps/unix/sysv/linux/alpha/globfree.c: Likewise.
    	* sysdeps/unix/sysv/linux/glob.c: Likewise.
    	* sysdeps/unix/sysv/linux/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/globfree.c: Likewise.
    	* sysdeps/unix/sysv/linux/globfree64.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/alphasort64.c: include olddirent.h
    	using relative path instead of absolute one.
    	* sysdeps/unix/sysv/linux/i386/getdents64.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/readdir64.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/readdir64_r.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/versionsort64.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/olddirent.h: Move to ...
    	* sysdeps/unix/sysv/linux/olddirent.h: ... here.
    	* sysdeps/unix/sysv/linux/i386/glob64.c: Move to ...
    	* sysdeps/unix/sysv/linux/oldglob.c: ... here.
    	* sysdeps/unix/sysv/linux/i386/glob64.c: Remove file.
    	* sysdeps/unix/sysv/linux/oldglob.c: New file.
    	* sysdeps/unix/sysv/linux/s390/s390-32/glob64.c: New file.
    	* sysdeps/unix/sysv/linux/s390/s390-32/oldglob.c: Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e0906fb5e1e3dd4ce487b8dc76e72035c21b9768

commit e0906fb5e1e3dd4ce487b8dc76e72035c21b9768
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed May 24 09:41:15 2017 -0300

    posix: Adjust glob tests to libsupport
    
    This patch adjust glob tests to use libsupport.  It also refactor some
    tests to move to a more meaningful file name and to gather similar tests
    in a common file:
    
      * move bug-glob3.c tests to tst-glob_basic.c.
      * move bug-glob2.c tests to tst-glob_memory.c
      * move common definitions to tst-glob_common.c.
    
    Checked on x86_64-linux-gnu.
    
    	* posix/Makefile (tests): Remove bug-glob2 and bug-glob3.  Add
    	tst-glob_basic and tst-glob_memory.
    	* posix/bug-glob3.c: Move to ...
    	* posix/tst-glob_basic.c: ... here.
    	* posix/bug-glob2.c: Move to ...
    	* posix/tst-glob_memory.c: ... here.
    	* posix/globtest.c: Use libsupport.
    	* posix/tst-gnuglob.c: Likewise.
    	* posix/tst-glob_common.c: New file.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c1ba9d146a5fd7522fa45f4309922f693e7470f5

commit c1ba9d146a5fd7522fa45f4309922f693e7470f5
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri May 19 12:39:47 2017 -0300

    posix: Allow glob to match dangling symlinks [BZ #866]
    
    This patch makes glob match dangling symlinks.  Compared to other glob
    implementation (*BSD, bash, musl, and other shells as well), GLIBC seems
    the be the only one that does not match dangling symlinks.  As for
    comment #5 in BZ #866, POSIX does not have any strict specification for
    dangling symlinks match and it is reasonable that trying to glob everything
    in a path should return all types of files (such as for a 'rm *').  Also,
    comment #7 shows even more example where GLIBC current behavior is
    unexepected.
    
    I avoided adding another GNU specific flag to set this behavior and
    instead make it the default.  Although this change the semanthic from
    previous implementation, I think adding another compat symbol to be
    really unecessary as from aforementioned reasons (current behavior not
    defined in any standard, general idea of different implementation is
    to list dangling symbols).
    
    Checked on x86_64-linux-gnu.
    
    	* posix/Makefile (tests): Add tst-glob_symlinks and remove tst-glob3.
    	* posix/bug-glob1.c: Remove file.
    	* posix/glob.c (glob): Match dangling symlinks.
    	(link_exists2_p): Remove function.
    	(link_exists_p): Likewise.
    	* posix/tst-glob_symlinks.c: New file.
    	* sysdeps/gnu/glob64.c (__stat): Redefine to __lstat.
    	* sysdeps/unix/sysv/linux/i386/glob64.c (__stat): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b80fb4bbc472522aeeafa148061a5a480300fb50

commit b80fb4bbc472522aeeafa148061a5a480300fb50
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed May 17 17:01:05 2017 -0300

    posix: Sync glob with gnulib [BZ #1062]
    
    This patch syncs posix/glob.c implementation with gnulib version
    1540f34.  The main differences to gnulib code:
    
      1. Commit 44c637c (Properly initialize glob structure with
         GLOB_BRACE|GLOB_DOOFFS) which fixes BZ# 20707.
    
      2. No inclusion of flexmember.h header and its usage on glob.
         The code is meant to be rewritten and header is unrequired in
         next patch in this set.
    
      3. An additional define (GLOB_COMPAT_BUILD) to avoid building
         size_and_wrapv and gblo_use_alloca twice on some configurations
         (i368 compat code) due multiple inclusion.
    
    The main changes are:
    
      - Header organization mostly due gnulib requirements.  It leads
        to some simplification and less conditional includes.
    
      - Use of glob_use_alloca with wraps up __libc_use_alloca with
        saturated math for the total size calculation.
    
      - Simplify some size allocation overflow calculation.
    
      - Some fixed on non supported glibc systems.
    
      - Some comments adjustments.
    
    The changes does not alter current glob internal semantic.  I also
    added a missing globfree on posix/globtest.c (it helps silence
    some valgrind or other memory profilers).
    
    	[BZ #1062]
    	* posix/glob.c: Sync with gnulib.
    	* posix/globtest.c (main): Add final globfree.
    	* sysdeps/unix/sysv/linux/i386/glob64.c (GLOB_COMPAT_BUILD):
    	Define.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=526d45c58ecbd329603c317bc5b80bfcfd6b08a1

commit 526d45c58ecbd329603c317bc5b80bfcfd6b08a1
Author: Florian Weimer <fweimer@redhat.com>
Date:   Tue Jun 20 10:31:28 2017 -0300

    gconv: Replace norm_add_slashes with __gconv_norm_add_slashes
    
    2017-06-19  Florian Weimer  <fweimer@redhat.com>
    	    Adhemerval Zanella  <adhemerval.zanella@linaro.org>
    
    	* iconv/Makefile (routine): Add norm_add_slashes.
    	* iconv/norm_add_slashes.c: New file, extracted from
    	iconv/gconv_int.h.
    	* iconv/gconv_int.h (norm_add_slashes): Remove.
    	(__gconv_norm_add_slashes): Declare.
    	* wcsmbs/wcsmbsload.c (__wcsmbs_load_conv): Use
    	__gconv_norm_add_slashes.
    	* intl/dcigettext.c (_nl_find_msg): Likewise.  Simplify !_LIBC
    	case.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e7ffd8ee94da45cb3433c29d36f4fd96bbd6b42a

commit e7ffd8ee94da45cb3433c29d36f4fd96bbd6b42a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jun 5 21:21:46 2017 -0300

    malloc: Add specialized dynarray for C strings
    
    This patch adds an specialized dynarray to manage C strings using the
    dynarray internal implementation.  It uses some private fields from
    dynarray and thus it provided specific files to access and manage
    the internal string buffer.
    
       For instance:
    
       struct char_array str;
       // str == "testing"
       char_array_init_str (&str, "testing");
       // c == 's'
       char c = char_array_pos (&str, 2);
       // str = "testing2"
       char_array_set_str (&str, "testing2");
       // str = "testi"
       char_array_erase (&str, 5);
       // str = "123testi"
       char_array_prepend_str (&str, "123");
       // len = 8
       size_t len = char_array_length (&str);
       // str = "123testi456"
       char_array_append_str (&str, "456");
       // str = "123testi789"
       char_array_replace_str_pos (&str, 7, "789", 3);
    
    The provided function are not extensive and meant mainly to be use in
    subsequent glob implementation cleanup.  For internal object consistency
    only the function provided by char_array.c should be used, including
    internal object manipulation.
    
    To check for possible overflows in internal size manipulation a new
    function, check_add_wrapv_size_t, is added on malloc-internal.  It basically
    return whether the addition of two size_t overflows.
    
    Checked on x86_64-linux-gnu.
    
    	* malloc/Makefile (test-internal): Add tst-char_array.
    	(routines): Add dynarray_overflow_failure and char_array-impl.
    	* malloc/Versions [GLIBC_PRIVATE] (libc): Add
    	__libc_dynarray_overflow_failure, __char_array_set_str_size,
    	__char_array_erase, __char_array_prepend_str_size, and
    	__char_array_replace_str_pos.
    	* malloc/char_array-impl.c: New file.
    	* malloc/char_array-skeleton.c: Likewise.
    	* malloc/char_array.h: Likewise.
    	* malloc/tst-char-array.c: Likewise.
    	* malloc/dynarray_overflow_failure.c: Likewise.
    	* malloc/malloc-internal.h (check_add_overflow_size_t): New function.

-----------------------------------------------------------------------
Comment 9 cvs-commit@gcc.gnu.org 2017-09-08 14:35:04 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  07b4f49db285f39594859c58893e3404b33200dd (commit)
       via  116f1c64d8d84ecbf269ac70a35657aa057f26c3 (commit)
       via  ffca890177bbf0980b66bc3a6d4d25c481957348 (commit)
       via  5a79f97554af6f2eb0a654f844b3d1f56937064d (commit)
       via  e00f2425996829632de5abff88bc1797558ce92e (commit)
       via  5554304f0dddf75dc27cc6250fc53355161fd16a (commit)
       via  686f2ea18374a541d203cfcc0e1dfba1666f49c2 (commit)
       via  c66c908230169c1bab1f83b071eb585baa214b9f (commit)
      from  78bfa877b36e8f33c99cbe9a16eb73f5a2adc0c8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=07b4f49db285f39594859c58893e3404b33200dd

commit 07b4f49db285f39594859c58893e3404b33200dd
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Sep 5 11:02:24 2017 -0300

    posix: Use enum for __glob_pattern_type result
    
    This patch replaces the internal integer constant from
    __glob_pattern_type return with a proper enum.
    
    Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
    for all major architectures.
    
    	* posix/glob_internal.h (glob_pattern_type_t): New enumeration.
    	(__glob_pattern_type): Use __glob_pat_types.
    	* posix/glob_pattern_p.c (__glob_pattern_p): Likewise.
    	* posix/glob.c (glob): Likewise.
    	(glob_in_dir): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=116f1c64d8d84ecbf269ac70a35657aa057f26c3

commit 116f1c64d8d84ecbf269ac70a35657aa057f26c3
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Sep 4 18:07:03 2017 -0300

    posix: Consolidate Linux glob implementation
    
    This patch consolidates the glob implementation.  The main changes are:
    
      * On Linux all implementation now uses the default one at
        sysdeps/unix/sysv/linux/glob{free}{64}.c with the exception
        of alpha (which requires specific versioning) and s390-32 (which
        different than other 32 bits ports it does not add a compat one
        symbol for 2.1 version).
    
      * The default implementation uses XSTAT_IS_XSTAT64 to define whether
        both glob{free} and glob{free}64 should be different implementations.
        For archictures that define XSTAT_IS_XSTAT64, glob{free} is an alias
        to glob{free}64.
    
      * Move i386 olddirent.h header to Linux default directory, since it is
        the only header with this name and it is shared among different
        architectures (and used on compat glob symbol as well).
    
    Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
    for all major architectures.
    
    	* sysdeps/unix/sysv/linux/arm/glob64.c: Remove file.
    	* sysdeps/unix/sysv/linux/i386/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips64/n64/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips64/n64/globfree64.c: Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/powerpc32/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/wordsize-64/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/wordsize-64/globfree64.c: Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/x32/glob.c: Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/x32/globfree.c: Likewise.
    	* sysdeps/wordsize-64/glob.c: Likewise.
    	* sysdeps/wordsize-64/glob64.c: Likewise.
    	* sysdeps/wordsize-64/globfree64.c: Likewise.
    	* sysdeps/unix/sysv/linux/glob.c: New file.
    	* sysdeps/unix/sysv/linux/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/globfree.c: Likewise.
    	* sysdeps/unix/sysv/linux/globfree64.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/glob64.c: Likewise.
    	* sysdeps/unix/sysv/linux/oldglob.c [SHLIB_COMPAT]: Also
    	adds !GLOB_NO_OLD_VERSION as an extra condition.
    	* sysdeps/unix/sysv/linux/i386/alphasort64.c: Include olddirent.h
    	using relative path instead of absolute one.
    	* sysdeps/unix/sysv/linux/i386/getdents64.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/readdir64.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/readdir64_r.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/versionsort64.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/olddirent.h: Move to ...
    	* sysdeps/unix/sysv/linux//olddirent.h: ... here.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ffca890177bbf0980b66bc3a6d4d25c481957348

commit ffca890177bbf0980b66bc3a6d4d25c481957348
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Sep 4 17:07:16 2017 -0300

    posix: fix glob bugs with long login names
    
    Current glob implementation allows unlimited user name for home
    directory construction on GLOB_TILDE case.  To accomplish it glob
    either construct a name on stack if size are small enough (based
    on current alloca_used) or in heap otherwise.
    
    This patch simplifies storage allocation by using the same scratch
    buffer for both get_rlogin_r and getpwnam_r.
    
    This also syncs with gnulib commit 064df0b (glob: fix bugs with long
    login names).
    
    Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
    for all major architectures.
    
    	* posix/glob.c (GET_LOGIN_NAME_MAX): Remove.
    	(glob): Use the same scratch buffer for both getlogin_r and
    	getpwnam_r.  Don’t require preallocation of the login name.  This
    	simplifies storage allocation, and corrects the handling of
    	long login names.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5a79f97554af6f2eb0a654f844b3d1f56937064d

commit 5a79f97554af6f2eb0a654f844b3d1f56937064d
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Sep 4 17:00:03 2017 -0300

    posix: Fix getpwnam_r usage (BZ #1062)
    
    This patch fixes longstanding misuse of errno after getpwnam_r,
    which returns an error number rather than setting errno.  This is
    sync with gnulib commit 5db9301.
    
    Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
    for all major architectures.
    
    	[BZ #1062]
    	* posix/glob.c (glob): Port recent patches to platforms
    	lacking getpwnam_r.
    	(glob): Fix longstanding misuse of errno after getpwnam_r, which
    	returns an error number rather than setting errno.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e00f2425996829632de5abff88bc1797558ce92e

commit e00f2425996829632de5abff88bc1797558ce92e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Sep 4 16:44:12 2017 -0300

    Sync scratch_buffer with gnulib
    
    This patch syncs the scratch_buffer grom gnulib commit 3866ef6 with
    GLIBC code.
    
    Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
    for all major architectures.
    
    	* include/scratch_buffer.h (scratch_buffer): Use a C99 align method
    	instead of GCC extension.
    	* malloc/scratch_buffer_grow.c [!_LIBC]: Include libc-config.h.
    	* malloc/scratch_buffer_grow_preserve.c [!_LIBC]: Likewise.
    	* malloc/scratch_buffer_set_array_size.c [!_LIBC]: Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5554304f0dddf75dc27cc6250fc53355161fd16a

commit 5554304f0dddf75dc27cc6250fc53355161fd16a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Sep 4 16:22:28 2017 -0300

    posix: Allow glob to match dangling symlinks [BZ #866]
    
    This patch makes glob match dangling symlinks.  Compared to other glob
    implementation (*BSD, bash, musl, and other shells as well), GLIBC seems
    the be the only one that does not match dangling symlinks.  As for
    comment #5 in BZ #866, POSIX does not have any strict specification for
    dangling symlinks match and it is reasonable that trying to glob everything
    in a path should return all types of files (such as for a 'rm *').  Also,
    comment #7 shows even more example where GLIBC current behavior is
    unexepected.
    
    I avoided adding another GNU specific flag to set this behavior and
    instead make it the default.  Although this change the semanthic from
    previous implementation, I think adding another compat symbol to be
    really unecessary as from aforementioned reasons (current behavior not
    defined in any standard, general idea of different implementation is
    to list dangling symbols).
    
    This also sync glob with gnulib commit fd1daf4 (glob: match dangling
    symlinks).
    
    Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
    for all major architectures.
    
    	[BZ #866]
    	[BZ #1062]
    	* posix/Makefile (tests): Remove bug-glob1 and tst-glob_symlinks.
    	* posix/bug-glob1.c: Remove file.
    	* posix/tst-glob_symlinks.c: New file.
    	* posix/glob.c (__lstat64): New macro.
    	(is_dir): New function.
    	(glob, glob_in_dir): Match symlinks even if they are dangling.
    	(link_stat, link_exists_p): Remove.  All uses removed.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=686f2ea18374a541d203cfcc0e1dfba1666f49c2

commit 686f2ea18374a541d203cfcc0e1dfba1666f49c2
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Sep 4 14:55:25 2017 -0300

    posix: accept inode 0 is a valid inode number (BZ #19971)
    
    According to this kernel commit 2adc376c55194, d_ino 0 is a regular inode
    number on Linux (which also matches POSIX, as it does not treat the value
    as special).  This patch makes glob accept is a valid inode number.
    
    This is also a sync with gnulib commit c8e57c1.
    
    Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
    for all major architectures.
    
    	[BZ #1062]
    	[BZ #19971]
    	* posix/glob.c (struct readdir_result): Remove skip_entry member.
    	(readdir_result_skip_entry, D_INO_TO_RESULT): Remove.
    	All uses removed.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c66c908230169c1bab1f83b071eb585baa214b9f

commit c66c908230169c1bab1f83b071eb585baa214b9f
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Sep 4 14:53:38 2017 -0300

    posix: Sync glob with gnulib [BZ #1062]
    
    This patch syncs posix/glob.c implementation with gnulib version
    b5ec983 (glob: simplify symlink detection).  The only difference
    to gnulib code is
    
      * DT_UNKNOWN, DT_DIR, and DT_LNK definition in the case there
        were not already defined.  Gnulib code which uses
        HAVE_STRUCT_DIRENT_D_TYPE will redefine them wrongly because
        GLIBC does not define HAVE_STRUCT_DIRENT_D_TYPE.  Instead
        the patch check for each definition instead.
    
    Also, the patch requires additional globfree and globfree64 files
    for compatibility version on some architectures.  Also the code
    simplification leads to not macro simplification (not need for
    NO_GLOB_PATTERN_P anymore).
    
    Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
    for all major architectures.
    
    	[BZ #1062]
    	* posix/Makefile (routines): Add globfree, globfree64, and
    	glob_pattern_p.
    	* posix/flexmember.h: New file.
    	* posix/glob_internal.h: Likewise.
    	* posix/glob_pattern_p.c: Likewise.
    	* posix/globfree.c: Likewise.
    	* posix/globfree64.c: Likewise.
    	* sysdeps/gnu/globfree64.c: Likewise.
    	* sysdeps/unix/sysv/linux/alpha/globfree.c: Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips64/n64/globfree64.c: Likewise.
    	* sysdeps/unix/sysv/linux/oldglob.c: Likewise.
    	* sysdeps/unix/sysv/linux/wordsize-64/globfree64.c: Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/x32/globfree.c: Likewise.
    	* sysdeps/wordsize-64/globfree.c: Likewise.
    	* sysdeps/wordsize-64/globfree64.c: Likewise.
    	* posix/glob.c (HAVE_CONFIG_H): Use !_LIBC instead.
    	[NDEBUG): Remove comments.
    	(GLOB_ONLY_P, _AMIGA, VMS): Remove define.
    	(dirent_type): New type.  Use uint_fast8_t not
    	uint8_t, as C99 does not require uint8_t.
    	(DT_UNKNOWN, DT_DIR, DT_LNK): New macros.
    	(struct readdir_result): Use dirent_type.  Do not define skip_entry
    	unless it is needed; this saves a byte on platforms lacking d_ino.
    	(readdir_result_type, readdir_result_skip_entry):
    	New functions, replacing ...
    	(readdir_result_might_be_symlink, readdir_result_might_be_dir):
    	 these functions, which were removed.  This makes the callers
    	easier to read.  All callers changed.
    	(D_INO_TO_RESULT): Now empty if there is no d_ino.
    	(size_add_wrapv, glob_use_alloca): New static functions.
    	(glob, glob_in_dir): Check for size_t overflow in several places,
    	and fix some size_t checks that were not quite right.
    	Remove old code using SHELL since Bash no longer
    	uses this.
    	(glob, prefix_array): Separate MS code better.
    	(glob_in_dir): Remove old Amiga and VMS code.
    	(globfree, __glob_pattern_type, __glob_pattern_p): Move to
    	separate files.
    	(glob_in_dir): Do not rely on undefined behavior in accessing
    	struct members beyond their bounds.  Use a flexible array member
    	instead
    	(link_stat): Rename from link_exists2_p and return -1/0 instead of
    	0/1.  Caller changed.
    	(glob): Fix memory leaks.
    	* posix/glob64 (globfree64): Move to separate file.
    	* sysdeps/gnu/glob64.c (NO_GLOB_PATTERN_P): Remove define.
    	(globfree64): Remove hidden alias.
    	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Add
    	oldglob.
    	* sysdeps/unix/sysv/linux/alpha/glob.c (__new_globfree): Move to
    	separate file.
    	* sysdeps/unix/sysv/linux/i386/glob64.c (NO_GLOB_PATTERN_P): Remove
    	define.
    	Move compat code to separate file.
    	* sysdeps/wordsize-64/glob.c (globfree): Move definitions to
    	separate file.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                          |  133 +++
 include/scratch_buffer.h                           |    3 +-
 malloc/scratch_buffer_grow.c                       |    6 +-
 malloc/scratch_buffer_grow_preserve.c              |    6 +-
 malloc/scratch_buffer_set_array_size.c             |    6 +-
 posix/Makefile                                     |    6 +-
 posix/bug-glob1.c                                  |   88 --
 posix/flexmember.h                                 |   45 +
 posix/glob.c                                       |  982 +++++++-------------
 posix/glob64.c                                     |    6 -
 posix/glob_internal.h                              |   65 ++
 posix/glob_pattern_p.c                             |   33 +
 posix/globfree.c                                   |   41 +
 posix/globfree64.c                                 |   31 +
 posix/tst-glob_symlinks.c                          |  135 +++
 sysdeps/gnu/glob64.c                               |    3 -
 sysdeps/gnu/globfree64.c                           |   10 +
 sysdeps/unix/sysv/linux/Makefile                   |    2 +-
 sysdeps/unix/sysv/linux/alpha/glob.c               |    4 -
 sysdeps/unix/sysv/linux/alpha/globfree.c           |   37 +
 sysdeps/unix/sysv/linux/arm/glob64.c               |    1 -
 sysdeps/unix/sysv/linux/glob.c                     |   28 +
 sysdeps/unix/sysv/linux/glob64.c                   |   51 +
 sysdeps/unix/sysv/linux/globfree.c                 |   30 +
 sysdeps/unix/sysv/linux/globfree64.c               |   36 +
 sysdeps/unix/sysv/linux/i386/alphasort64.c         |    2 +-
 sysdeps/unix/sysv/linux/i386/getdents64.c          |    2 +-
 sysdeps/unix/sysv/linux/i386/glob64.c              |   79 --
 sysdeps/unix/sysv/linux/i386/readdir64.c           |    2 +-
 sysdeps/unix/sysv/linux/i386/readdir64_r.c         |    2 +-
 sysdeps/unix/sysv/linux/i386/versionsort64.c       |    2 +-
 sysdeps/unix/sysv/linux/m68k/glob64.c              |    1 -
 sysdeps/unix/sysv/linux/mips/mips64/n64/glob64.c   |    1 -
 sysdeps/unix/sysv/linux/{i386 => }/olddirent.h     |    0
 sysdeps/unix/sysv/linux/oldglob.c                  |   43 +
 sysdeps/unix/sysv/linux/powerpc/powerpc32/glob64.c |    1 -
 sysdeps/unix/sysv/linux/s390/s390-32/glob64.c      |    2 +
 sysdeps/unix/sysv/linux/sparc/sparc32/glob64.c     |    1 -
 sysdeps/unix/sysv/linux/wordsize-64/glob64.c       |    2 -
 sysdeps/unix/sysv/linux/x86_64/x32/glob.c          |    1 -
 sysdeps/wordsize-64/glob.c                         |    8 -
 sysdeps/wordsize-64/glob64.c                       |    1 -
 42 files changed, 1103 insertions(+), 835 deletions(-)
 delete mode 100644 posix/bug-glob1.c
 create mode 100644 posix/flexmember.h
 create mode 100644 posix/glob_internal.h
 create mode 100644 posix/glob_pattern_p.c
 create mode 100644 posix/globfree.c
 create mode 100644 posix/globfree64.c
 create mode 100644 posix/tst-glob_symlinks.c
 create mode 100644 sysdeps/gnu/globfree64.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/globfree.c
 delete mode 100644 sysdeps/unix/sysv/linux/arm/glob64.c
 create mode 100644 sysdeps/unix/sysv/linux/glob.c
 create mode 100644 sysdeps/unix/sysv/linux/glob64.c
 create mode 100644 sysdeps/unix/sysv/linux/globfree.c
 create mode 100644 sysdeps/unix/sysv/linux/globfree64.c
 delete mode 100644 sysdeps/unix/sysv/linux/i386/glob64.c
 delete mode 100644 sysdeps/unix/sysv/linux/m68k/glob64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/n64/glob64.c
 rename sysdeps/unix/sysv/linux/{i386 => }/olddirent.h (100%)
 create mode 100644 sysdeps/unix/sysv/linux/oldglob.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/glob64.c
 create mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/glob64.c
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/glob64.c
 delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/glob64.c
 delete mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/glob.c
 delete mode 100644 sysdeps/wordsize-64/glob.c
 delete mode 100644 sysdeps/wordsize-64/glob64.c
Comment 10 Adhemerval Zanella 2017-09-08 14:38:36 UTC
Fixed by 5554304f0d.