bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ls segfault - coreutils-6.5


From: Paul Eggert
Subject: Re: ls segfault - coreutils-6.5
Date: Mon, 20 Nov 2006 01:13:43 -0800
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Greg Schafer <address@hidden> writes:

> Admnittedly, this is an unusual situation in that it's inside an almost
> empty chroot environment before everything is sane ie: it's part of my
> "bootstrap a whole new world" procedure. Here is a backtrace. Hope it helps:
>
> (gdb) bt
> #0  0xb7e7ceb3 in strlen () from /temptools/lib/libc.so.6
> #1  0x08053265 in getgroup (gid=0) at idcache.c:146

Ouch, thanks for reporting that.  This bug is my fault; sorry.
I didn't notice that the idcache code cached the absence of groups.

I installed the following obvious quick patch into gnulib; it should
fix your coreutils problem (apply just the idcache.c fix).

2006-11-20  Paul Eggert  <address@hidden>

        * 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.

Index: lib/idcache.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/idcache.c,v
retrieving revision 1.18
diff -p -u -r1.18 idcache.c
--- lib/idcache.c       6 Nov 2006 22:02:53 -0000       1.18
+++ lib/idcache.c       20 Nov 2006 09:08:56 -0000
@@ -19,7 +19,6 @@
 
 #include <config.h>
 
-#include <stddef.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
@@ -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)
Index: modules/idcache
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/idcache,v
retrieving revision 1.8
diff -p -u -r1.8 idcache
--- modules/idcache     6 Nov 2006 22:02:53 -0000       1.8
+++ modules/idcache     20 Nov 2006 09:08:56 -0000
@@ -6,7 +6,6 @@ lib/idcache.c
 m4/idcache.m4
 
 Depends-on:
-flexmember
 xalloc
 
 configure.ac:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]