summaryrefslogtreecommitdiffstats
path: root/sbin/ping
diff options
context:
space:
mode:
authormaxim <maxim@FreeBSD.org>2003-01-23 13:04:42 +0000
committermaxim <maxim@FreeBSD.org>2003-01-23 13:04:42 +0000
commit14d7bf5dd29c2c39953da0220b454c8fd9eedabc (patch)
treed3d55bcb73b28afde296acd471de56a6233e2b9b /sbin/ping
parent08b55cf1d9ee9c5758741e3b83621dffe665ee07 (diff)
downloadFreeBSD-src-14d7bf5dd29c2c39953da0220b454c8fd9eedabc.zip
FreeBSD-src-14d7bf5dd29c2c39953da0220b454c8fd9eedabc.tar.gz
Better error handling for -s.
Submitted by: bde Do not constantify maximum payload size. It is 65467 with -R (record route), and 65507 without it. Reviewed by: silence on -net Proposed by: bde I am going to MFC rev.1.77 - 1.81 ping.c and rev.1.39 and 1.40 ping.8: MFC after: 6 months
Diffstat (limited to 'sbin/ping')
-rw-r--r--sbin/ping/ping.82
-rw-r--r--sbin/ping/ping.c24
2 files changed, 15 insertions, 11 deletions
diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8
index 105e5f1..5aa26fa 100644
--- a/sbin/ping/ping.8
+++ b/sbin/ping/ping.8
@@ -235,7 +235,7 @@ data bytes when combined
with the 8 bytes of
.Tn ICMP
header data.
-Only the super-user may use this option.
+Only the super-user may specify values more than default.
.It Fl S Ar src_addr
Use the following IP address as the source address in outgoing packets.
On hosts with more than one IP address, this option can be used to
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index 96757be..7953649 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -104,7 +104,6 @@ static const char rcsid[] =
#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)
#define MAXICMPLEN (ICMP_ADVLENMIN + MAX_IPOPTLEN)
#define MINICMPLEN ICMP_MINLEN
-#define MAXPAYLOAD (IP_MAXPACKET - MAXIPLEN - MINICMPLEN)
#define MAXWAIT 10 /* max seconds to wait for response */
#define MAXALARM (60 * 60) /* max seconds for alarm timeout */
#define MAXTOS 255
@@ -151,6 +150,7 @@ int mx_dup_ck = MAX_DUP_CHK;
char rcvd_tbl[MAX_DUP_CHK / 8];
struct sockaddr_in whereto; /* who to ping */
+long maxpayload;
int datalen = DEFDATALEN;
int s; /* socket file descriptor */
u_char outpackhdr[IP_MAXPACKET], *outpack;
@@ -351,18 +351,16 @@ main(argc, argv)
options |= F_SO_DONTROUTE;
break;
case 's': /* size of packet to send */
- if (uid) {
- errno = EPERM;
- err(EX_NOPERM, "-s flag");
- }
ultmp = strtoul(optarg, &ep, 0);
- if (ultmp > MAXPAYLOAD)
- errx(EX_USAGE,
- "packet size too large: %lu > %u",
- ultmp, MAXPAYLOAD);
if (*ep || ep == optarg)
errx(EX_USAGE, "invalid packet size: `%s'",
optarg);
+ if (uid != 0 && ultmp > DEFDATALEN) {
+ errno = EPERM;
+ err(EX_NOPERM,
+ "packet size too large: %lu > %u",
+ ultmp, DEFDATALEN);
+ }
datalen = ultmp;
break;
case 'S':
@@ -418,6 +416,12 @@ main(argc, argv)
usage();
target = argv[optind];
+ maxpayload = IP_MAXPACKET - sizeof(struct ip) - MINICMPLEN;
+ if (options & F_RROUTE)
+ maxpayload -= MAX_IPOPTLEN;
+ if (datalen > maxpayload)
+ errx(EX_USAGE, "packet size too large: %lu > %u", datalen,
+ maxpayload);
if (source) {
bzero((char *)&sin, sizeof(sin));
sin.sin_family = AF_INET;
@@ -1477,7 +1481,7 @@ fill(bp, patp)
&pat[13], &pat[14], &pat[15]);
if (ii > 0)
- for (kk = 0; kk <= MAXPAYLOAD - (PHDR_LEN + ii); kk += ii)
+ for (kk = 0; kk <= maxpayload - (PHDR_LEN + ii); kk += ii)
for (jj = 0; jj < ii; ++jj)
bp[jj + kk] = pat[jj];
if (!(options & F_QUIET)) {
OpenPOWER on IntegriCloud