]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
posix: Use malloc instead of alloca for the glob user name
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 31 Jul 2026 16:37:17 +0000 (16:37 +0000)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Sun, 9 Aug 2026 11:53:55 +0000 (08:53 -0300)
Use malloc unconditionally.  The name is only needed for the passwd
lookup that follows, which is far more expensive than the allocation.

Checked on x86_64-linux-gnu, aarch64-linux-gnu, and i686-linux-gnu.

Reviewed-by: Collin Funk <collin.funk1@gmail.com>
posix/glob.c

index 0e9bf02bb4eef43143cca927ab1de991f191202f..a3c1f888d5470fd3a457502062daa4d1c37ae69e 100644 (file)
@@ -828,19 +828,13 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
             user_name = dirname + 1;
           else
             {
-              char *newp;
-              if (glob_use_alloca (alloca_used, end_name - dirname))
-                newp = alloca_account (end_name - dirname, alloca_used);
-              else
+              char *newp = malloc (end_name - dirname);
+              if (newp == NULL)
                 {
-                  newp = malloc (end_name - dirname);
-                  if (newp == NULL)
-                    {
-                      retval = GLOB_NOSPACE;
-                      goto out;
-                    }
-                  malloc_user_name = 1;
+                  retval = GLOB_NOSPACE;
+                  goto out;
                 }
+              malloc_user_name = 1;
               if (unescape != NULL)
                 {
                   char *p = mempcpy (newp, dirname + 1,