diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-07-23 10:31:29 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-07-23 10:31:29 +0000 |
commit | 5740a64046bbc3d976589eabe913efacb653fd48 (patch) | |
tree | 9660adcef062891a478421b6c2d7a7083bc05fbb /sbin/ping/ping.c | |
parent | 756ce2f0953ebbdd452295be27cb68e354b2f9c3 (diff) |
ptrace is safe; limit preload to root
Diffstat (limited to 'sbin/ping/ping.c')
-rw-r--r-- | sbin/ping/ping.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 49c0a225354..3eac8259be3 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping.c,v 1.6 1996/07/23 08:36:44 deraadt Exp $ */ +/* $OpenBSD: ping.c,v 1.7 1996/07/23 10:31:28 deraadt Exp $ */ /* $NetBSD: ping.c,v 1.20 1995/08/11 22:37:58 cgd Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$OpenBSD: ping.c,v 1.6 1996/07/23 08:36:44 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ping.c,v 1.7 1996/07/23 10:31:28 deraadt Exp $"; #endif #endif /* not lint */ @@ -182,7 +182,7 @@ main(argc, argv) struct protoent *proto; struct in_addr saddr; register int i; - int ch, fdmask, hold, packlen, preload; + int ch, fdmask, hold = 1, packlen, preload; u_char *datap, *packet; char *target, hnamebuf[MAXHOSTNAMELEN]; u_char ttl = MAXTTL, loop = 1, df = 0; @@ -191,6 +191,14 @@ main(argc, argv) char rspace[3 + 4 * NROUTES + 1]; /* record route space */ #endif + if (!(proto = getprotobyname("icmp"))) + errx(1, "unknown protocol icmp"); + if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) + err(1, "socket"); + + /* revoke privs */ + setuid(getuid()); + preload = 0; datap = &outpack[8 + sizeof(struct timeval)]; while ((ch = getopt(argc, argv, "DI:LRS:c:dfh:i:l:np:qrs:T:t:vw:")) != EOF) @@ -235,6 +243,8 @@ main(argc, argv) loop = 0; break; case 'l': + if (getuid() != 0) + errx(1, "must be root to specify preload"); preload = strtol(optarg, NULL, 0); if (preload < 0) errx(1, "bad preload value: %s", optarg); @@ -324,12 +334,6 @@ main(argc, argv) ident = getpid() & 0xFFFF; - if (!(proto = getprotobyname("icmp"))) - errx(1, "unknown protocol icmp"); - if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) - err(1, "socket"); - hold = 1; - if (options & F_SADDR) { if (IN_MULTICAST(ntohl(to->sin_addr.s_addr))) moptions |= MULTICAST_IF; |