diff options
author | deraadt <> | 2016-06-27 23:58:08 +0000 |
---|---|---|
committer | deraadt <> | 2016-06-27 23:58:08 +0000 |
commit | e98b18a04d6a9fa587f5470e19fc94d5364b2ad9 (patch) | |
tree | 58c34f46558e14753ac9d7e0889e8465d5822b18 | |
parent | 97835ed91473716ba1fc9d9c313df25fabd42fd8 (diff) | |
download | openbsd-e98b18a04d6a9fa587f5470e19fc94d5364b2ad9.tar.gz openbsd-e98b18a04d6a9fa587f5470e19fc94d5364b2ad9.tar.bz2 openbsd-e98b18a04d6a9fa587f5470e19fc94d5364b2ad9.zip |
Be more careful initializing and tracking socket s through main, this is
so complicated that a future refactoring could easily in introduce a bug.
ok millert krw
-rw-r--r-- | src/usr.bin/nc/netcat.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index cf8a87d883..ba7e88af55 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.153 2016/06/02 04:26:32 beck Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.154 2016/06/27 23:58:08 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * Copyright (c) 2015 Bob Beck. All rights reserved. | 4 | * Copyright (c) 2015 Bob Beck. All rights reserved. |
@@ -144,7 +144,7 @@ struct tls *tls_setup_server(struct tls *, int, char *); | |||
144 | int | 144 | int |
145 | main(int argc, char *argv[]) | 145 | main(int argc, char *argv[]) |
146 | { | 146 | { |
147 | int ch, s, ret, socksv; | 147 | int ch, s = -1, ret, socksv; |
148 | char *host, *uport; | 148 | char *host, *uport; |
149 | struct addrinfo hints; | 149 | struct addrinfo hints; |
150 | struct servent *sv; | 150 | struct servent *sv; |
@@ -158,7 +158,6 @@ main(int argc, char *argv[]) | |||
158 | struct tls *tls_ctx = NULL; | 158 | struct tls *tls_ctx = NULL; |
159 | 159 | ||
160 | ret = 1; | 160 | ret = 1; |
161 | s = 0; | ||
162 | socksv = 5; | 161 | socksv = 5; |
163 | host = NULL; | 162 | host = NULL; |
164 | uport = NULL; | 163 | uport = NULL; |
@@ -586,8 +585,8 @@ main(int argc, char *argv[]) | |||
586 | build_ports(uport); | 585 | build_ports(uport); |
587 | 586 | ||
588 | /* Cycle through portlist, connecting to each port. */ | 587 | /* Cycle through portlist, connecting to each port. */ |
589 | for (i = 0; portlist[i] != NULL; i++) { | 588 | for (s = -1, i = 0; portlist[i] != NULL; i++) { |
590 | if (s) | 589 | if (s != -1) |
591 | close(s); | 590 | close(s); |
592 | 591 | ||
593 | if (usetls) { | 592 | if (usetls) { |
@@ -604,7 +603,7 @@ main(int argc, char *argv[]) | |||
604 | else | 603 | else |
605 | s = remote_connect(host, portlist[i], hints); | 604 | s = remote_connect(host, portlist[i], hints); |
606 | 605 | ||
607 | if (s < 0) | 606 | if (s == -1) |
608 | continue; | 607 | continue; |
609 | 608 | ||
610 | ret = 0; | 609 | ret = 0; |
@@ -653,7 +652,7 @@ main(int argc, char *argv[]) | |||
653 | } | 652 | } |
654 | } | 653 | } |
655 | 654 | ||
656 | if (s) | 655 | if (s != -1) |
657 | close(s); | 656 | close(s); |
658 | 657 | ||
659 | tls_config_free(tls_cfg); | 658 | tls_config_free(tls_cfg); |