[PATCH] posix: execvpe: skip $PATH components that are too long
Pádraig Brady
P@draigBrady.com
Tue Dec 23 19:19:32 GMT 2025
On 23/12/2025 18:22, Adhemerval Zanella Netto wrote:
>
> I think it makes sense to handle ENAMETOOLONG as ENOENT, ESTALE, ENOTDIR,
> ENODEV, and ETIMEDOUT. It is consistency with the systems (BSDs) and how
> other executors already handle it (shells).
...
> I think we also need to check if the output of the command execution
> does match what we expect ("foo\n"). Something like:
>
> --
>
> #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)
> {
> int fd;
> TEST_VERIFY_EXIT ((fd = create_temp_file ("testscript", &fname)) != -1);
>
> dprintf (fd, "echo foo\n");
> TEST_VERIFY_EXIT (fchmod (fd, 0700) == 0);
> xclose (fd);
> }
> #define PREPARE do_prepare
>
> static void
> run_execvpe (void *closure)
> {
> char *argv[] = { fname, NULL };
> execvpe (basename (fname), argv, NULL);
>
> support_record_failure ();
> }
>
> static int
> do_test (void)
> {
> /* Linux 6.17 at least will give ENAMETOOLONG once any
> path component is > NAME_MAX, so ensure we skip such paths
> rather than failing. [BZ #33626] */
> char *path = xasprintf ("%*s:%s", NAME_MAX+1, "", test_dir);
> TEST_VERIFY_EXIT (setenv ("PATH", path, 1) == 0);
> free (path);
>
> struct support_capture_subprocess result
> = support_capture_subprocess (run_execvpe, NULL);
> support_capture_subprocess_check (&result, "execvpe", 0, sc_allow_stdout);
>
> TEST_COMPARE_STRING (result.out.buffer, "foo\n");
>
> support_capture_subprocess_free (&result);
>
> return 0;
> }
>
> #include <support/test-driver.c>
Cool, I've updated the test with that in the attached.
I also fixed up the test file description.
The test passes, and fails with the code change reverted.
thanks!
Padraig
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v3-glibc-execvpe-enametoolong.patch
Type: text/x-patch
Size: 4131 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20251223/e5b2e1ab/attachment.bin>
More information about the Libc-alpha
mailing list