bug-coreutils
[Top][All Lists]
Advanced

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

Re: Problems on darwin with coreutils-6.10.133-677610


From: Jim Meyering
Subject: Re: Problems on darwin with coreutils-6.10.133-677610
Date: Tue, 25 Mar 2008 22:47:52 +0100

Peter Fales <address@hidden> wrote:
> Trying to build http://meyering.net/cu/coreutils-6.10.133-677610.tar.gz
> and getting test failures on darwin (Mac OS/X), as  "id -G" is returning
> incorrect values.  It seems that in id.c, we have
>
>       214       user_name = pwd ? pwd->pw_name : NULL;
>
> where user_name caches a value returned by getpwuid().  However, down
> in print_group_list() at line 43, getpwuid() is called again, and it
> causes the value pointed to by username to be corrupted.   I've attached
> a patch which appears to help.
...
> diff -ur coreutils-6.10.133-677610/src/id.c 
> coreutils-6.10.133-677610.new/src/id.c
> --- coreutils-6.10.133-677610/src/id.c        2008-03-13 18:09:44.000000000 
> -0500
> +++ coreutils-6.10.133-677610.new/src/id.c    2008-03-24 11:38:14.000000000 
> -0500
> @@ -211,7 +211,7 @@
>        struct passwd const *pwd;
>        euid = geteuid ();
>        pwd = getpwuid (euid);
> -      user_name = pwd ? pwd->pw_name : NULL;
> +      user_name = pwd ? strdup(pwd->pw_name) : NULL;

Thanks a lot!
I'm applying this patch:

>From f7d1c59c224f81a8bab5fa2afcaf815988f50467 Mon Sep 17 00:00:00 2001
From: Peter Fales <address@hidden>
Date: Tue, 25 Mar 2008 22:44:01 +0100
Subject: [PATCH] id bug fix: don't point to potentially clobbered static storage

On at least Mac OS, when calling getpwuid twice with the same UID,
the static storage containing results from the first call is
invalidated by the second call.
* src/id.c (main): Point to a copy of the user name string.

Signed-off-by: Jim Meyering <address@hidden>
---
 src/id.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/id.c b/src/id.c
index 9ee52e1..a178714 100644
--- a/src/id.c
+++ b/src/id.c
@@ -211,7 +211,7 @@ of a different user"));
       struct passwd const *pwd;
       euid = geteuid ();
       pwd = getpwuid (euid);
-      user_name = pwd ? pwd->pw_name : NULL;
+      user_name = pwd ? xstrdup (pwd->pw_name) : NULL;
       ruid = getuid ();
       egid = getegid ();
       rgid = getgid ();
--
1.5.5.rc0.22.g467c




reply via email to

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