Submitted By: Jim Gifford Date: 2006-11-20 Initial Package Version: 6.5 Upstream Status: Applied Origin: http://lists.gnu.org/archive/html/bug-coreutils/2006-11/msg00156.html Description: Fixes a segfault with in ls diff -Naur coreutils-6.5.orig/lib/idcache.c coreutils-6.5/lib/idcache.c --- coreutils-6.5.orig/lib/idcache.c 2006-11-07 06:42:11.000000000 -0800 +++ coreutils-6.5/lib/idcache.c 2006-11-20 23:16:09.000000000 -0800 @@ -19,7 +19,6 @@ #include -#include #include #include #include @@ -41,8 +40,8 @@ uid_t u; gid_t g; } id; + char *name; struct userid *next; - char name[FLEXIBLE_ARRAY_MEMBER]; }; static struct userid *user_alist; @@ -57,17 +56,15 @@ { register struct userid *tail; struct passwd *pwent; - char const *name; for (tail = user_alist; tail; tail = tail->next) if (tail->id.u == uid) return tail->name; pwent = getpwuid (uid); - name = pwent ? pwent->pw_name : ""; - tail = xmalloc (offsetof (struct userid, name) + strlen (name) + 1); + tail = xmalloc (sizeof *tail); tail->id.u = uid; - strcpy (tail->name, name); + tail->name = pwent ? xstrdup (pwent->pw_name) : NULL; /* Add to the head of the list, so most recently used is first. */ tail->next = user_alist; @@ -107,8 +104,8 @@ } #endif - tail = xmalloc (offsetof (struct userid, name) + strlen (user) + 1); - strcpy (tail->name, user); + tail = xmalloc (sizeof *tail); + tail->name = xstrdup (user); /* Add to the head of the list, so most recently used is first. */ if (pwent) @@ -135,17 +132,15 @@ { register struct userid *tail; struct group *grent; - char const *name; for (tail = group_alist; tail; tail = tail->next) if (tail->id.g == gid) return tail->name; grent = getgrgid (gid); - name = grent ? grent->gr_name : NULL; - tail = xmalloc (offsetof (struct userid, name) + strlen (name) + 1); + tail = xmalloc (sizeof *tail); tail->id.g = gid; - strcpy (tail->name, name); + tail->name = grent ? xstrdup (grent->gr_name) : NULL; /* Add to the head of the list, so most recently used is first. */ tail->next = group_alist; @@ -185,8 +180,8 @@ } #endif - tail = xmalloc (offsetof (struct userid, name) + strlen (group) + 1); - strcpy (tail->name, group); + tail = xmalloc (sizeof *tail); + tail->name = xstrdup (group); /* Add to the head of the list, so most recently used is first. */ if (grent)