--- Begin Message ---
Subject: |
[PATCH id] Add error-checking on GNU |
Date: |
Fri, 11 Nov 2011 20:31:57 +0100 |
User-agent: |
Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux) |
Hello,
On GNU, processes can have zero or more UIDs/GIDs. In the case of a
process with zero UIDs, for instance, ‘getuid’ returns -1 and sets
ERRNO [0] (as an extension to POSIX [1].)
Currently ‘id’ would print (unsigned int) -1 as the UID in that case,
whereas it should rather print an error. The attached patch does that.
(Note that the Hurd comes with another utility, called ‘ids’, which
prints all the (E)[UG]IDs of the process and gracefully handles the
zero-UID/GID case [2].)
Thanks,
Ludo’.
[0]
http://git.savannah.gnu.org/cgit/hurd/glibc.git/tree/sysdeps/mach/hurd/getuid.c
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/getuid.html
[2] http://git.savannah.gnu.org/cgit/hurd/hurd.git/tree/utils/ids.c
diff --git a/src/id.c b/src/id.c
index f80fcd1..824a471 100644
--- a/src/id.c
+++ b/src/id.c
@@ -202,9 +202,28 @@ main (int argc, char **argv)
else
{
euid = geteuid ();
+#ifdef __GNU__
+ if (euid == -1)
+ error (EXIT_FAILURE, errno, _("Cannot get effective UID"));
+#endif
+
ruid = getuid ();
+#ifdef __GNU__
+ if (ruid == -1)
+ error (EXIT_FAILURE, errno, _("Cannot get real UID"));
+#endif
+
egid = getegid ();
+#ifdef __GNU__
+ if (egid == -1)
+ error (EXIT_FAILURE, errno, _("Cannot get effective GID"));
+#endif
+
rgid = getgid ();
+#ifdef __GNU__
+ if (rgid == -1)
+ error (EXIT_FAILURE, errno, _("Cannot get real GID"));
+#endif
}
if (just_user)
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#10021: [PATCH id] Add error-checking on GNU |
Date: |
Sat, 19 Nov 2011 19:23:16 +0100 |
Paul Eggert wrote:
> I found yet-another tricky bug in that id.c code,
> and fixed it as follows:
>
> Subject: [PATCH] id: fix bug when euid != ruid
>
> * src/id.c (main): Report an error if no args are given and getuid
> fails, because print_full_info needs ruid. Redo code so that
> getuid and friends are invoked only when needed; this makes the
> code easier to follow, and is how I found the above bug.
Thanks.
I've marked this as done.
--- End Message ---