aboutsummaryrefslogtreecommitdiff
path: root/sbin/ping6
diff options
context:
space:
mode:
authorYoshinobu Inoue <shin@FreeBSD.org>2000-02-24 19:06:05 +0000
committerYoshinobu Inoue <shin@FreeBSD.org>2000-02-24 19:06:05 +0000
commit53c9088f688ee6fee2a93029f8eb2612d7afd01c (patch)
tree4f2070445af713d1e5a582adfc84126342f7abf9 /sbin/ping6
parent88a845c11d2f2056fe0249f52144e77e1dcdf41a (diff)
downloadsrc-53c9088f688ee6fee2a93029f8eb2612d7afd01c.tar.gz
src-53c9088f688ee6fee2a93029f8eb2612d7afd01c.zip
Security fixes. (Just same as sbin/ping and usr.sbin/traceroute)
-Open socket() at first and then setuid() to actual user. -Allow ping6 preload option only for root. Approved by: jkh Submitted by: Neil Blakey-Milner <nbm@mithrandr.moria.org>
Notes
Notes: svn path=/head/; revision=57439
Diffstat (limited to 'sbin/ping6')
-rw-r--r--sbin/ping6/ping6.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c
index 34de2bdc00b4..00f06e378a46 100644
--- a/sbin/ping6/ping6.c
+++ b/sbin/ping6/ping6.c
@@ -269,6 +269,10 @@ main(argc, argv)
memset(&smsghdr, 0, sizeof(&smsghdr));
memset(&smsgiov, 0, sizeof(&smsgiov));
+ if ((s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0)
+ err(1, "socket");
+ setuid(getuid());
+
preload = 0;
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
#ifndef IPSEC
@@ -356,6 +360,10 @@ main(argc, argv)
options |= F_INTERVAL;
break;
case 'l':
+ if (getuid()) {
+ errno = EPERM;
+ errx(1, "Must be superuser to preload");
+ }
preload = strtol(optarg, &e, 10);
if (preload < 0 || *optarg == '\0' || *e != '\0')
errx(1, "illegal preload value -- %s", optarg);
@@ -462,9 +470,6 @@ main(argc, argv)
ident = getpid() & 0xFFFF;
- if ((s = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0)
- err(1, "socket");
-
hold = 1;
if (options & F_SO_DEBUG)