diff options
author | Eric Jackson <ericj@cvs.openbsd.org> | 2001-06-26 21:57:36 +0000 |
---|---|---|
committer | Eric Jackson <ericj@cvs.openbsd.org> | 2001-06-26 21:57:36 +0000 |
commit | 77682e0d8d22531ed2952aaab30aae7c69483b3d (patch) | |
tree | c151ed79d6b6f7b36e796c534ad11f0cc8f12a8a /usr.bin/nc | |
parent | 88503806779a6e4f43aa4e2795034a0680740304 (diff) |
be weary of atoi().
suggested by theo.. also do range checking on ports
Diffstat (limited to 'usr.bin/nc')
-rw-r--r-- | usr.bin/nc/netcat.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index 2d179f559d4..70d98da2b1e 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.25 2001/06/26 21:19:14 ericj Exp $ */ +/* $OpenBSD: netcat.c,v 1.26 2001/06/26 21:57:35 ericj Exp $ */ /* * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> * @@ -79,7 +79,7 @@ main(argc, argv) char *argv[]; { int ch, s, ret = 1; - char *host, *uport; + char *host, *uport, *endp; struct addrinfo hints; struct servent *sv = 0; socklen_t len; @@ -97,7 +97,9 @@ main(argc, argv) help(); break; case 'i': - iflag = atoi(optarg); + iflag = (int)strtoul(optarg, &endp, 10); + if (iflag < 0 || *endp != '\0') + errx(1, "interval cannot be negative"); break; case 'k': kflag = 1; @@ -126,8 +128,10 @@ main(argc, argv) case 'v': vflag = 1; break; - case 'w': - timeout = atoi(optarg); + case 'w': + timeout = (int)strtoul(optarg, &endp, 10); + if (timeout < 0 || *endp != '\0') + errx(1, "timeout cannot be negative"); break; case 'z': zflag = 1; @@ -476,7 +480,7 @@ void build_ports(p) char *p; { - char *n; + char *n, *endp; int hi, lo, cp; int x = 0; @@ -488,8 +492,12 @@ build_ports(p) n++; /* Make sure the ports are in order: lowest->highest */ - hi = atoi(n); - lo = atoi(p); + hi = (int)strtoul(n, &endp, 10); + if (hi <= 0 || hi > 65535 || *endp != '\0') + errx(1, "port range not valid"); + lo = (int)strtoul(p, &endp, 10); + if (lo <= 0 || lo > 65535 || *endp != '\0') + errx(1, "port range not valid"); if (lo > hi) { cp = hi; @@ -517,6 +525,9 @@ build_ports(p) } } } else { + hi = (int)strtoul(p, &endp, 10); + if (hi <= 0 || hi > 65535 || *endp != '\0') + errx(1, "port range not valid"); portlist[0] = malloc(sizeof(65535)); portlist[0] = p; } |