svn commit: r351216 - head/sbin/ping6

Alan Somers asomers at FreeBSD.org
Mon Aug 19 14:20:27 UTC 2019


Author: asomers
Date: Mon Aug 19 14:20:26 2019
New Revision: 351216
URL: https://svnweb.freebsd.org/changeset/base/351216

Log:
  ping6: revert r350857
  
  Some socket options require root privileges to set.  The old code did indeed
  drop privileges at the earliest opportunity.
  
  Submitted by:	Ján Sučan <sucanjan at gmail.com>
  MFC after:	Never
  Sponsored by:	Google, Inc. (Google Summer of Code 2019)
  Differential Revision:	https://reviews.freebsd.org/D21319

Modified:
  head/sbin/ping6/ping6.c

Modified: head/sbin/ping6/ping6.c
==============================================================================
--- head/sbin/ping6/ping6.c	Mon Aug 19 14:11:54 2019	(r351215)
+++ head/sbin/ping6/ping6.c	Mon Aug 19 14:20:26 2019	(r351216)
@@ -663,12 +663,6 @@ main(int argc, char *argv[])
 		err(1, "socket srecv");
 	freeaddrinfo(res);
 
-	/* revoke root privilege */
-	if (seteuid(getuid()) != 0)
-		err(1, "seteuid() failed");
-	if (setuid(getuid()) != 0)
-		err(1, "setuid() failed");
-
 	/* set the source address if specified. */
 	if ((options & F_SRCADDR) != 0) {
 		/* properly fill sin6_scope_id */
@@ -738,6 +732,12 @@ main(int argc, char *argv[])
 			err(1, "setsockopt(IPV6_RECVRTHDRDSTOPTS)");
 #endif
 	}
+
+	/* revoke root privilege */
+	if (seteuid(getuid()) != 0)
+		err(1, "seteuid() failed");
+	if (setuid(getuid()) != 0)
+		err(1, "setuid() failed");
 
 	if ((options & F_FLOOD) && (options & F_INTERVAL))
 		errx(1, "-f and -i incompatible options");


More information about the svn-src-head mailing list