740027
diff -urNp coreutils-8.4-orig/src/id.c coreutils-8.4/src/id.c
740027
--- coreutils-8.4-orig/src/id.c	2014-06-26 08:47:28.435047859 +0200
740027
+++ coreutils-8.4/src/id.c	2014-06-26 08:55:28.352788022 +0200
740027
@@ -296,8 +296,12 @@ print_full_info (const char *username)
740027
     gid_t *groups;
740027
     int i;
740027
 
740027
-    int n_groups = xgetgroups (username, (pwd ? pwd->pw_gid : -1),
740027
-                               &groups);
740027
+    gid_t primary_group;
740027
+    if (username)
740027
+      primary_group = pwd ? pwd->pw_gid : -1;
740027
+    else
740027
+      primary_group = egid;
740027
+    int n_groups = xgetgroups (username, primary_group, &groups);
740027
     if (n_groups < 0)
740027
       {
740027
         if (username)
740027
740027
diff -urNp coreutils-8.22-orig/tests/id/setgid.sh coreutils-8.22/tests/id/setgid.sh
740027
--- coreutils-8.22-orig/tests/id/setgid.sh	2014-06-26 08:47:28.750053213 +0200
740027
+++ coreutils-8.22/tests/id/setgid.sh	2014-06-26 08:51:02.536624404 +0200
740027
@@ -1,5 +1,5 @@
740027
 #!/bin/sh
740027
-# Verify that id -G prints the right group when run set-GID.
740027
+# Verify that id [-G] prints the right group when run set-GID.
740027
 
740027
 # Copyright (C) 2012-2013 Free Software Foundation, Inc.
740027
 
740027
@@ -35,4 +35,9 @@ setuidgid -g $gp1 $NON_ROOT_USERNAME env
740027
 compare exp out || fail=1
740027
 # With coreutils-8.16 and earlier, id -G would print both: $gp1 $g
740027
 
740027
+# With coreutils-8.22 and earlier, id would erroneously print groups=$g
740027
+chroot --user=$NON_ROOT_USERNAME:$gp1 --groups='' / env PATH="$PATH" \
740027
+  id > out || fail=1
740027
+grep -F "groups=$gp1" out || fail=1
740027
+
740027
 Exit $fail