View | Details | Raw Unified | Return to bug 56614 | Differences between
and this patch

Collapse All | Expand All

(-)files/patch-main.c (+53 lines)
Added Link Here
1
--- main.c.orig	Tue Sep  9 01:24:31 2003
2
+++ main.c	Tue Sep  9 01:29:26 2003
3
@@ -448,29 +448,17 @@
4
 	char		*cp, *np;
5
 	struct passwd	*pw;
6
 	struct group	*gr;
7
-	int		ngroups, gidset[256];
8
+	int		ngroups = 0, gidset[256];
9
 	int		curenv = 0, curarg = 0;
10
 	char		*new_envp[MAXENV];
11
 	char		*new_argv[MAXARG];
12
 	char		str[MAXSTRLEN], buf[4*MAXSTRLEN];
13
 
14
-	if ((cp = FindOpt(cmd, "uid")) == NULL) {
15
-		if (setuid(0) < 0)
16
-			fatal("Unable to set uid to default", cp);
17
-	} else {
18
-		if ((pw = getpwnam(cp)) == NULL) {
19
-			if (setuid(atoi(cp)) < 0)
20
-				fatal("Unable to set uid to %s", cp);
21
-		}
22
-		if (setuid(pw->pw_uid) < 0)
23
-			fatal("Unable to set uid to %s", cp);
24
-	}
25
-
26
 	if ((cp = FindOpt(cmd, "gid")) == NULL) {
27
 		;		/* don't have a default */
28
 	} else {
29
 		for (cp=GetField(cp, str); cp!=NULL; cp=GetField(cp, str)) {
30
-			if ((gr = getgrnam(cp)) != NULL)
31
+			if ((gr = getgrnam(str)) != NULL)
32
 				gidset[ngroups++] = gr->gr_gid;
33
 		}
34
 		if (ngroups == 0) 
35
@@ -533,6 +521,18 @@
36
 			new_envp[curenv++] = environ[i];
37
 	}
38
 	new_envp[curenv] = NULL;
39
+
40
+	if ((cp = FindOpt(cmd, "uid")) == NULL) {
41
+		if (setuid(0) < 0)
42
+			fatal("Unable to set uid to default", cp);
43
+	} else {
44
+		if ((pw = getpwnam(cp)) == NULL) {
45
+			if (setuid(atoi(cp)) < 0)
46
+				fatal("Unable to set uid to %s", cp);
47
+		}
48
+		if (setuid(pw->pw_uid) < 0)
49
+			fatal("Unable to set uid to %s", cp);
50
+	}
51
 
52
 	if (strcmp("MAGIC_SHELL", cmd->args[0]) == 0) {
53
 		for (i = 0; environ[i] != NULL; i++) 

Return to bug 56614