source:
patches/coreutils-6.5-id_cache-1.patch@
ceba886d
Last change on this file since ceba886d was be36855, checked in by , 18 years ago | |
---|---|
|
|
File size: 2.5 KB |
-
lib/idcache.c
Submitted By: Jim Gifford <jim at linuxfromscratch dot org> 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
old new 19 19 20 20 #include <config.h> 21 21 22 #include <stddef.h>23 22 #include <stdio.h> 24 23 #include <string.h> 25 24 #include <sys/types.h> … … 41 40 uid_t u; 42 41 gid_t g; 43 42 } id; 43 char *name; 44 44 struct userid *next; 45 char name[FLEXIBLE_ARRAY_MEMBER];46 45 }; 47 46 48 47 static struct userid *user_alist; … … 57 56 { 58 57 register struct userid *tail; 59 58 struct passwd *pwent; 60 char const *name;61 59 62 60 for (tail = user_alist; tail; tail = tail->next) 63 61 if (tail->id.u == uid) 64 62 return tail->name; 65 63 66 64 pwent = getpwuid (uid); 67 name = pwent ? pwent->pw_name : ""; 68 tail = xmalloc (offsetof (struct userid, name) + strlen (name) + 1); 65 tail = xmalloc (sizeof *tail); 69 66 tail->id.u = uid; 70 strcpy (tail->name, name);67 tail->name = pwent ? xstrdup (pwent->pw_name) : NULL; 71 68 72 69 /* Add to the head of the list, so most recently used is first. */ 73 70 tail->next = user_alist; … … 107 104 } 108 105 #endif 109 106 110 tail = xmalloc ( offsetof (struct userid, name) + strlen (user) + 1);111 strcpy (tail->name,user);107 tail = xmalloc (sizeof *tail); 108 tail->name = xstrdup (user); 112 109 113 110 /* Add to the head of the list, so most recently used is first. */ 114 111 if (pwent) … … 135 132 { 136 133 register struct userid *tail; 137 134 struct group *grent; 138 char const *name;139 135 140 136 for (tail = group_alist; tail; tail = tail->next) 141 137 if (tail->id.g == gid) 142 138 return tail->name; 143 139 144 140 grent = getgrgid (gid); 145 name = grent ? grent->gr_name : NULL; 146 tail = xmalloc (offsetof (struct userid, name) + strlen (name) + 1); 141 tail = xmalloc (sizeof *tail); 147 142 tail->id.g = gid; 148 strcpy (tail->name, name);143 tail->name = grent ? xstrdup (grent->gr_name) : NULL; 149 144 150 145 /* Add to the head of the list, so most recently used is first. */ 151 146 tail->next = group_alist; … … 185 180 } 186 181 #endif 187 182 188 tail = xmalloc ( offsetof (struct userid, name) + strlen (group) + 1);189 strcpy (tail->name,group);183 tail = xmalloc (sizeof *tail); 184 tail->name = xstrdup (group); 190 185 191 186 /* Add to the head of the list, so most recently used is first. */ 192 187 if (grent)
Note:
See TracBrowser
for help on using the repository browser.