[Midnightbsd-cvs] src [8282] trunk: check the return error of set[e][ug]id

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Sep 17 18:02:15 EDT 2016


Revision: 8282
          http://svnweb.midnightbsd.org/src/?rev=8282
Author:   laffer1
Date:     2016-09-17 18:02:15 -0400 (Sat, 17 Sep 2016)
Log Message:
-----------
check the return error of set[e][ug]id

Modified Paths:
--------------
    trunk/libexec/tftpd/tftpd.c
    trunk/sbin/ccdconfig/ccdconfig.c
    trunk/sbin/restore/tape.c
    trunk/usr.bin/lock/lock.c
    trunk/usr.bin/msgs/msgs.c
    trunk/usr.sbin/edquota/edquota.c
    trunk/usr.sbin/kgmon/kgmon.c

Modified: trunk/libexec/tftpd/tftpd.c
===================================================================
--- trunk/libexec/tftpd/tftpd.c	2016-09-17 22:00:13 UTC (rev 8281)
+++ trunk/libexec/tftpd/tftpd.c	2016-09-17 22:02:15 UTC (rev 8282)
@@ -371,7 +371,10 @@
 		}
 		chdir("/");
 		setgroups(1, &nobody->pw_gid);
-		setuid(nobody->pw_uid);
+		if (setuid(nobody->pw_uid) != 0) {
+			tftp_log(LOG_ERR, "setuid failed");
+			exit(1);
+		}
 	}
 
 	len = sizeof(me_sock);

Modified: trunk/sbin/ccdconfig/ccdconfig.c
===================================================================
--- trunk/sbin/ccdconfig/ccdconfig.c	2016-09-17 22:00:13 UTC (rev 8281)
+++ trunk/sbin/ccdconfig/ccdconfig.c	2016-09-17 22:02:15 UTC (rev 8282)
@@ -288,13 +288,16 @@
 
 	rval = 0;
 	egid = getegid();
-	setegid(getgid());
+	if (setegid(getgid()) != 0)
+		err(1, "setegid failed");
 	if ((f = fopen(ccdconf, "r")) == NULL) {
-		setegid(egid);
+		if (setegid(egid) != 0)
+			err(1, "setegid failed");
 		warn("fopen: %s", ccdconf);
 		return (1);
 	}
-	setegid(egid);
+	if (setegid(egid) != 0)
+		err(1, "setegid failed");
 
 	while (fgets(line, sizeof(line), f) != NULL) {
 		argc = 0;

Modified: trunk/sbin/restore/tape.c
===================================================================
--- trunk/sbin/restore/tape.c	2016-09-17 22:00:13 UTC (rev 8281)
+++ trunk/sbin/restore/tape.c	2016-09-17 22:02:15 UTC (rev 8282)
@@ -164,7 +164,11 @@
 		}
 		pipein++;
 	}
-	setuid(getuid());	/* no longer need or want root privileges */
+	/* no longer need or want root privileges */
+	if (setuid(getuid()) != 0) {
+		fprintf(stderr, "setuid failed\n");
+		done(1);
+	}
 	magtape = strdup(source);
 	if (magtape == NULL) {
 		fprintf(stderr, "Cannot allocate space for magtape buffer\n");

Modified: trunk/usr.bin/lock/lock.c
===================================================================
--- trunk/usr.bin/lock/lock.c	2016-09-17 22:00:13 UTC (rev 8281)
+++ trunk/usr.bin/lock/lock.c	2016-09-17 22:02:15 UTC (rev 8282)
@@ -129,7 +129,9 @@
 		}
 	timeout.tv_sec = sectimeout * 60;
 
-	setuid(getuid());		/* discard privs */
+	/* discard privs */
+	if (setuid(getuid()) != 0)
+		errx(1, "setuid failed");
 
 	if (tcgetattr(0, &tty))		/* get information for header */
 		exit(1);

Modified: trunk/usr.bin/msgs/msgs.c
===================================================================
--- trunk/usr.bin/msgs/msgs.c	2016-09-17 22:00:13 UTC (rev 8281)
+++ trunk/usr.bin/msgs/msgs.c	2016-09-17 22:02:15 UTC (rev 8282)
@@ -175,7 +175,8 @@
 	setlocale(LC_ALL, "");
 
 	time(&t);
-	setuid(uid = getuid());
+	if (setuid(uid = getuid()) != 0)
+		err(1, "setuid failed");
 	ruptible = (signal(SIGINT, SIG_IGN) == SIG_DFL);
 	if (ruptible)
 		signal(SIGINT, SIG_DFL);

Modified: trunk/usr.sbin/edquota/edquota.c
===================================================================
--- trunk/usr.sbin/edquota/edquota.c	2016-09-17 22:00:13 UTC (rev 8281)
+++ trunk/usr.sbin/edquota/edquota.c	2016-09-17 22:02:15 UTC (rev 8282)
@@ -453,8 +453,10 @@
 		const char *ed;
 
 		sigsetmask(omask);
-		setgid(getgid());
-		setuid(getuid());
+		if (setgid(getgid()) != 0)
+			err(1, "setgid failed");
+		if (setuid(getuid()) != 0)
+			err(1, "setuid failed");
 		if ((ed = getenv("EDITOR")) == (char *)0)
 			ed = _PATH_VI;
 		execlp(ed, ed, tmpf, (char *)0);

Modified: trunk/usr.sbin/kgmon/kgmon.c
===================================================================
--- trunk/usr.sbin/kgmon/kgmon.c	2016-09-17 22:00:13 UTC (rev 8281)
+++ trunk/usr.sbin/kgmon/kgmon.c	2016-09-17 22:02:15 UTC (rev 8282)
@@ -90,7 +90,9 @@
 	struct kvmvars kvmvars;
 	char *system, *kmemf;
 
-	seteuid(getuid());
+	if (seteuid(getuid()) != 0) {
+		err(1, "seteuid failed\n");
+	}
 	kmemf = NULL;
 	system = NULL;
 	while ((ch = getopt(argc, argv, "M:N:Bbhpr")) != -1) {



More information about the Midnightbsd-cvs mailing list