[glibc] posix: Use malloc instead of alloca for the glob user name

Adhemerval Zanella via Glibc-cvs <[email protected]>
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d0084cbd1835b344eb2cb14f00e486a676fc0623

commit d0084cbd1835b344eb2cb14f00e486a676fc0623
Author: Adhemerval Zanella <[email protected]>
Date:   Fri Jul 31 16:37:17 2026 +0000

    posix: Use malloc instead of alloca for the glob user name
    
    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 <[email protected]>

Diff:
---
 posix/glob.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/posix/glob.c b/posix/glob.c
index 0e9bf02bb4..a3c1f888d5 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -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,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.