[PATCH] posix: execvpe: skip $PATH components that are too long [BZ #33626]

Collin Funk collin.funk1@gmail.com
Sat Feb 14 04:16:35 GMT 2026


Pádraig Brady <P@draigBrady.com> writes:

> * posix/execvpe.c (__execvpe_common): Rather than error out
> with ENAMETOOLONG, just ignore and try the next path.
> Note we know the FILE length is <= NAME_MAX, so the ENAMETOOLONG
> almost certainly pertains to the current $PATH entry.
> * posix/tst-execvpe7.c: A new test based on tst-execvp3.c.
> * posix/Makefile: Reference the new test.
> ---
>  posix/Makefile       |  1 +
>  posix/execvpe.c      |  3 ++
>  posix/tst-execvpe7.c | 74 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 78 insertions(+)
>  create mode 100644 posix/tst-execvpe7.c
>
> diff --git a/posix/Makefile b/posix/Makefile
> index f377948462..ec28b9e1da 100644
> --- a/posix/Makefile
> +++ b/posix/Makefile
> @@ -277,6 +277,7 @@ tests := \
>    tst-execvpe4 \
>    tst-execvpe5 \
>    tst-execvpe6 \
> +  tst-execvpe7 \
>    tst-fexecve \
>    tst-fnmatch \
>    tst-fnmatch2 \
> diff --git a/posix/execvpe.c b/posix/execvpe.c
> index 29e8bcd3d1..ec56e297b0 100644
> --- a/posix/execvpe.c
> +++ b/posix/execvpe.c
> @@ -157,6 +157,9 @@ __execvpe_common (const char *file, char *const argv[], char *const envp[],
>  	  /* Those errors indicate the file is missing or not executable
>  	     by us, in which case we want to just try the next path
>  	     directory.  */
> +	  case ENAMETOOLONG:
> +	  /* We've already verified that the FILE length is < NAME_MAX,
> +	     so this implies a path component is too long, so skip it.  */
>  	  case ENODEV:
>  	  case ETIMEDOUT:
>  	  /* Some strange filesystems like AFS return even
> diff --git a/posix/tst-execvpe7.c b/posix/tst-execvpe7.c
> new file mode 100644
> index 0000000000..d6d9d70c4e
> --- /dev/null
> +++ b/posix/tst-execvpe7.c
> @@ -0,0 +1,74 @@
> +/* Check execvpe does not fail when encountering long $PATH components.
> +   Copyright (C) 2016-2025 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <stdlib.h>
> +#include <libgen.h>
> +#include <limits.h>
> +
> +#include <support/capture_subprocess.h>
> +#include <support/check.h>
> +#include <support/support.h>
> +#include <support/temp_file.h>
> +#include <support/test-driver.h>
> +#include <support/xunistd.h>
> +
> +static char *fname;
> +
> +static void
> +do_prepare (int c, char** argv)

I will change that to "char **argv" locally:

    $ git grep -F 'char**' -- '*.[ch]'
    posix/tst-execvpe7.c:do_prepare (int c, char** argv)

But otherwise looks good.

Reviewed-by: Collin Funk <collin.funk1@gmail.com>

Will give Adhemerval some time to look. I forgot if he gave a
Reviewed-by on the previous version of this patch or not.

Collin


More information about the Libc-alpha mailing list