File: local-initgroups-order.diff

package info (click to toggle)
glibc 2.28-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 271,524 kB
  • sloc: ansic: 1,008,513; asm: 259,608; makefile: 11,266; sh: 10,477; python: 6,910; cpp: 4,992; perl: 2,258; awk: 2,005; yacc: 290; pascal: 182; sed: 73
file content (38 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (34)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

 setgroups(size, groups) changes egid on kfreebsd, 
 precisely groups[0] is the new egid

 initgroups(user, gid) prepares the "groups" list
 via internal_getgrouplist(). 
 It puts supplied gid as the first entry in all but NSCD cases.
 Fix the remaining NSCD case, see #698102, #699593.


--- a/nscd/nscd_initgroups.c
+++ b/nscd/nscd_initgroups.c
@@ -145,15 +145,23 @@
     }
 
   /* Check whether GROUP is part of the mix.  If not, add it.  */
+  /* The GROUP have to be in the first entry */
   if (retval >= 0)
     {
       int cnt;
+      gid_t sg, tg;
+      sg = group;
       for (cnt = 0; cnt < retval; ++cnt)
-	if ((*groupsp)[cnt] == group)
+      {
+        tg = (*groupsp)[cnt];
+        (*groupsp)[cnt] = sg;
+        if (tg == group)
 	  break;
+        sg = tg;
+      }  
 
       if (cnt == retval)
-	(*groupsp)[retval++] = group;
+	(*groupsp)[retval++] = sg;
     }
 
  out_close: