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