bug-hurd
[Top][All Lists]
Advanced

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

Re: bug#10021: [PATCH id] Add error-checking on GNU


From: Jim Meyering
Subject: Re: bug#10021: [PATCH id] Add error-checking on GNU
Date: Tue, 15 Nov 2011 18:10:40 +0100

Paul Eggert wrote:
> On 11/15/11 05:07, Ludovic Courtès wrote:
>
>> On GNU/Hurd, no error would ever be raised (since uid_t is unsigned),
>
> Ouch.  Thanks, now I understand Roland's suggestion.
> How about this patch instead?
>
> id: handle (uid_t) -1 more portably
> * src/id.c (GETID_MAY_FAIL): Remove.
> (main): Check for nonzero errno, rather than having a compile-time
> GETID_MAY_FAIL guess.  Suggested by Roland McGrath in
> <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10021#47>.
> Also, the old code was incorrect if uid_t was narrower than int.
> (print_full_info): Remove unnecessary cast to -1.
> diff --git a/src/id.c b/src/id.c
> index 047e40b..9fa93f8 100644
> --- a/src/id.c
> +++ b/src/id.c
> @@ -38,13 +38,6 @@
>    proper_name ("Arnold Robbins"), \
>    proper_name ("David MacKenzie")
>
> -/* Whether the functions getuid, geteuid, getgid and getegid may fail.  */
> -#ifdef __GNU__
> -# define GETID_MAY_FAIL 1
> -#else
> -# define GETID_MAY_FAIL 0
> -#endif
> -
>  /* If nonzero, output only the SELinux context. -Z */
>  static int just_context = 0;
>
> @@ -208,22 +201,32 @@ main (int argc, char **argv)
>      }
>    else
>      {
> +      /* POSIX says getuid etc. cannot fail, but they can fail under
> +         GNU/Hurd and a few other systems.  Test for failure by
> +         checking errno.  */
> +      uid_t NO_UID = -1;
> +      gid_t NO_GID = -1;
> +
> +      errno = 0;
>        euid = geteuid ();
> -      if (GETID_MAY_FAIL && euid == -1 && !use_real
> +      if (euid == NO_UID && errno && !use_real

I like that.  Thanks!



reply via email to

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