diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2015-02-11 09:49:39 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2015-02-11 09:49:39 +0000 |
commit | d476df7f070b3cdb22e3e9731165e1152440a526 (patch) | |
tree | cd19060d4f766fffe0054386da1f076718a08a84 /usr.sbin/traceroute | |
parent | 7fd6020fee22def0491c12722a867c75ee637d2f (diff) |
Replace base 10 strtol with strtonum.
OK krw@, tedu@, deraadt@
Diffstat (limited to 'usr.sbin/traceroute')
-rw-r--r-- | usr.sbin/traceroute/traceroute.c | 80 |
1 files changed, 31 insertions, 49 deletions
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c index d3623ccd888..89ba5d01660 100644 --- a/usr.sbin/traceroute/traceroute.c +++ b/usr.sbin/traceroute/traceroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: traceroute.c,v 1.137 2015/02/09 23:00:15 deraadt Exp $ */ +/* $OpenBSD: traceroute.c,v 1.138 2015/02/11 09:49:38 florian Exp $ */ /* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */ /* @@ -452,12 +452,9 @@ main(int argc, char *argv[]) dump = 1; break; case 'f': - errno = 0; - ep = NULL; - l = strtol(optarg, &ep, 10); - if (errno || !*optarg || *ep || l < 1 || l > max_ttl) + first_ttl = strtonum(optarg, 1, max_ttl, &errstr); + if (errstr) errx(1, "min ttl must be 1 to %u.", max_ttl); - first_ttl = (u_int8_t)l; break; case 'g': if (lsrr >= MAX_LSRR) @@ -483,35 +480,25 @@ main(int argc, char *argv[]) ttl_flag = 1; break; case 'm': - errno = 0; - ep = NULL; - l = strtol(optarg, &ep, 10); - if (errno || !*optarg || *ep || l < first_ttl || - l > MAXTTL) + max_ttl = strtonum(optarg, first_ttl, MAXTTL, &errstr); + if (errstr) errx(1, "max ttl must be %u to %u.", first_ttl, MAXTTL); - max_ttl = (u_int8_t)l; break; case 'n': nflag = 1; break; case 'p': - errno = 0; - ep = NULL; - l = strtol(optarg, &ep, 10); - if (errno || !*optarg || *ep || l <= 0 || l >= 65536) + port = strtonum(optarg, 1, 65535, &errstr); + if (errstr) errx(1, "port must be >0, <65536."); - port = (u_int16_t)l; break; case 'P': if (protoset) errx(1, "protocol already set with -I"); protoset = 1; - errno = 0; - ep = NULL; - l = strtol(optarg, &ep, 10); - if (errno || !*optarg || *ep || l < 1 || - l >= IPPROTO_MAX) { + proto = strtonum(optarg, 1, IPPROTO_MAX - 1, &errstr); + if (errstr) { struct protoent *pent; pent = getprotobyname(optarg); @@ -520,16 +507,12 @@ main(int argc, char *argv[]) else errx(1, "proto must be >=1, or a " "name."); - } else - proto = (int)l; + } break; case 'q': - errno = 0; - ep = NULL; - l = strtol(optarg, &ep, 10); - if (errno || !*optarg || *ep || l < 1 || l > INT_MAX) + nprobes = strtonum(optarg, 1, INT_MAX, &errstr); + if (errstr) errx(1, "nprobes must be >0."); - nprobes = (int)l; break; case 's': /* @@ -543,17 +526,22 @@ main(int argc, char *argv[]) break; case 't': if (!map_tos(optarg, &tos)) { - errno = 0; - errstr = NULL; if (strlen(optarg) > 1 && optarg[0] == '0' && - optarg[1] == 'x') - tos = (int)strtol(optarg, NULL, 16); - else - tos = (int)strtonum(optarg, 0, 255, - &errstr); - if (tos < 0 || tos > 255 || errstr || errno) - errx(1, "illegal tos value %s", - optarg); + optarg[1] == 'x') { + errno = 0; + ep = NULL; + l = strtol(optarg, &ep, 16); + if (errno || !*optarg || *ep || + l < 0 || l > 255) + errx(1, "illegal tos value %s", + optarg); + tos = (int)l; + } else { + tos = strtonum(optarg, 0, 255, &errstr); + if (errstr) + errx(1, "illegal tos value %s", + optarg); + } } tflag = 1; last_tos = tos; @@ -575,12 +563,9 @@ main(int argc, char *argv[]) err(1, "setsockopt SO_RTABLE"); break; case 'w': - errno = 0; - ep = NULL; - l = strtol(optarg, &ep, 10); - if (errno || !*optarg || *ep || l <= 1 || l > INT_MAX) + waittime = strtonum(optarg, 2, INT_MAX, &errstr); + if (errstr) errx(1, "wait must be >1 sec."); - waittime = (int)l; break; case 'x': xflag = 1; @@ -658,12 +643,9 @@ main(int argc, char *argv[]) freeaddrinfo(res); if (*++argv) { - errno = 0; - ep = NULL; - l = strtol(*argv, &ep, 10); - if (errno || !*argv || *ep || l < 0 || l > INT_MAX) + datalen = strtonum(*argv, 0, INT_MAX, &errstr); + if (errstr) errx(1, "datalen out of range"); - datalen = (int)l; } switch (to->sa_family) { |