From d1f50b65154ba8ed20b3b42650e3bf4e774908f4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 20 Nov 2006 09:10:18 +0000 Subject: [PATCH] * lib/idcache.c: Undo most recent patch, dated 2006-11-06. It mishandled the case where the group was missing. Problem reported by Greg Schafer. * modules/idcache: Likewise. --- ChangeLog | 7 +++++++ lib/idcache.c | 23 +++++++++-------------- modules/idcache | 1 - 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 016e7338a..222053c7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-11-20 Paul Eggert + + * lib/idcache.c: Undo most recent patch, dated 2006-11-06. + It mishandled the case where the group was missing. + Problem reported by Greg Schafer. + * modules/idcache: Likewise. + 2006-11-18 Jim Meyering * check-module (%exempt_header): Add exception for some diff --git a/lib/idcache.c b/lib/idcache.c index 02e30e3e9..d4a867d7b 100644 --- a/lib/idcache.c +++ b/lib/idcache.c @@ -19,7 +19,6 @@ #include -#include #include #include #include @@ -41,8 +40,8 @@ struct userid 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 @@ getuser (uid_t uid) { 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 @@ getuidbyname (const char *user) } #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 @@ getgroup (gid_t gid) { 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 @@ getgidbyname (const char *group) } #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) diff --git a/modules/idcache b/modules/idcache index 97cc71498..05923d020 100644 --- a/modules/idcache +++ b/modules/idcache @@ -6,7 +6,6 @@ lib/idcache.c m4/idcache.m4 Depends-on: -flexmember xalloc configure.ac: -- 2.11.0