diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/usr.bin/nc/netcat.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index bea1b79ba5..20571aab68 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: netcat.c,v 1.87 2006/02/01 21:33:14 otto Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.88 2006/06/02 03:46:38 ray Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
| 4 | * | 4 | * |
| @@ -65,7 +65,7 @@ | |||
| 65 | 65 | ||
| 66 | /* Command Line Options */ | 66 | /* Command Line Options */ |
| 67 | int dflag; /* detached, no stdin */ | 67 | int dflag; /* detached, no stdin */ |
| 68 | int iflag; /* Interval Flag */ | 68 | unsigned int iflag; /* Interval Flag */ |
| 69 | int jflag; /* use jumbo frames if we can */ | 69 | int jflag; /* use jumbo frames if we can */ |
| 70 | int kflag; /* More than one connect */ | 70 | int kflag; /* More than one connect */ |
| 71 | int lflag; /* Bind to local port */ | 71 | int lflag; /* Bind to local port */ |
| @@ -106,13 +106,13 @@ int | |||
| 106 | main(int argc, char *argv[]) | 106 | main(int argc, char *argv[]) |
| 107 | { | 107 | { |
| 108 | int ch, s, ret, socksv; | 108 | int ch, s, ret, socksv; |
| 109 | char *host, *uport, *endp; | 109 | char *host, *uport; |
| 110 | struct addrinfo hints; | 110 | struct addrinfo hints; |
| 111 | struct servent *sv; | 111 | struct servent *sv; |
| 112 | socklen_t len; | 112 | socklen_t len; |
| 113 | struct sockaddr_storage cliaddr; | 113 | struct sockaddr_storage cliaddr; |
| 114 | char *proxy; | 114 | char *proxy; |
| 115 | const char *proxyhost = "", *proxyport = NULL; | 115 | const char *errstr, *proxyhost = "", *proxyport = NULL; |
| 116 | struct addrinfo proxyhints; | 116 | struct addrinfo proxyhints; |
| 117 | 117 | ||
| 118 | ret = 1; | 118 | ret = 1; |
| @@ -120,7 +120,6 @@ main(int argc, char *argv[]) | |||
| 120 | socksv = 5; | 120 | socksv = 5; |
| 121 | host = NULL; | 121 | host = NULL; |
| 122 | uport = NULL; | 122 | uport = NULL; |
| 123 | endp = NULL; | ||
| 124 | sv = NULL; | 123 | sv = NULL; |
| 125 | 124 | ||
| 126 | while ((ch = getopt(argc, argv, | 125 | while ((ch = getopt(argc, argv, |
| @@ -152,9 +151,9 @@ main(int argc, char *argv[]) | |||
| 152 | help(); | 151 | help(); |
| 153 | break; | 152 | break; |
| 154 | case 'i': | 153 | case 'i': |
| 155 | iflag = (int)strtoul(optarg, &endp, 10); | 154 | iflag = strtonum(optarg, 0, UINT_MAX, &errstr); |
| 156 | if (iflag < 0 || *endp != '\0') | 155 | if (errstr) |
| 157 | errx(1, "interval cannot be negative"); | 156 | errx(1, "interval %s: %s", errstr, optarg); |
| 158 | break; | 157 | break; |
| 159 | case 'j': | 158 | case 'j': |
| 160 | jflag = 1; | 159 | jflag = 1; |
| @@ -190,11 +189,9 @@ main(int argc, char *argv[]) | |||
| 190 | vflag = 1; | 189 | vflag = 1; |
| 191 | break; | 190 | break; |
| 192 | case 'w': | 191 | case 'w': |
| 193 | timeout = (int)strtoul(optarg, &endp, 10); | 192 | timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr); |
| 194 | if (timeout < 0 || *endp != '\0') | 193 | if (errstr) |
| 195 | errx(1, "timeout cannot be negative"); | 194 | errx(1, "timeout %s: %s", errstr, optarg); |
| 196 | if (timeout >= (INT_MAX / 1000)) | ||
| 197 | errx(1, "timeout too large"); | ||
| 198 | timeout *= 1000; | 195 | timeout *= 1000; |
| 199 | break; | 196 | break; |
| 200 | case 'x': | 197 | case 'x': |
| @@ -681,7 +678,8 @@ atelnet(int nfd, unsigned char *buf, unsigned int size) | |||
| 681 | void | 678 | void |
| 682 | build_ports(char *p) | 679 | build_ports(char *p) |
| 683 | { | 680 | { |
| 684 | char *n, *endp; | 681 | const char *errstr; |
| 682 | char *n; | ||
| 685 | int hi, lo, cp; | 683 | int hi, lo, cp; |
| 686 | int x = 0; | 684 | int x = 0; |
| 687 | 685 | ||
| @@ -693,12 +691,12 @@ build_ports(char *p) | |||
| 693 | n++; | 691 | n++; |
| 694 | 692 | ||
| 695 | /* Make sure the ports are in order: lowest->highest. */ | 693 | /* Make sure the ports are in order: lowest->highest. */ |
| 696 | hi = (int)strtoul(n, &endp, 10); | 694 | hi = strtonum(n, 1, PORT_MAX, &errstr); |
| 697 | if (hi <= 0 || hi > PORT_MAX || *endp != '\0') | 695 | if (errstr) |
| 698 | errx(1, "port range not valid"); | 696 | errx(1, "port number %s: %s", errstr, n); |
| 699 | lo = (int)strtoul(p, &endp, 10); | 697 | lo = strtonum(p, 1, PORT_MAX, &errstr); |
| 700 | if (lo <= 0 || lo > PORT_MAX || *endp != '\0') | 698 | if (errstr) |
| 701 | errx(1, "port range not valid"); | 699 | errx(1, "port number %s: %s", errstr, p); |
| 702 | 700 | ||
| 703 | if (lo > hi) { | 701 | if (lo > hi) { |
| 704 | cp = hi; | 702 | cp = hi; |
| @@ -728,9 +726,9 @@ build_ports(char *p) | |||
| 728 | } | 726 | } |
| 729 | } | 727 | } |
| 730 | } else { | 728 | } else { |
| 731 | hi = (int)strtoul(p, &endp, 10); | 729 | hi = strtonum(p, 1, PORT_MAX, &errstr); |
| 732 | if (hi <= 0 || hi > PORT_MAX || *endp != '\0') | 730 | if (errstr) |
| 733 | errx(1, "port range not valid"); | 731 | errx(1, "port number %s: %s", errstr, p); |
| 734 | portlist[0] = calloc(1, PORT_MAX_LEN); | 732 | portlist[0] = calloc(1, PORT_MAX_LEN); |
| 735 | if (portlist[0] == NULL) | 733 | if (portlist[0] == NULL) |
| 736 | err(1, NULL); | 734 | err(1, NULL); |
