summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2016-06-27 23:58:09 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2016-06-27 23:58:09 +0000
commit2c08429fc6b36ffe748b5ae8ec8ff79d68d326b0 (patch)
tree2cd20c29ed9b2482a67a411df25976060612aa03 /usr.bin
parent2d54722cd224c37d1e8c65de8b9a5e0e5db698af (diff)
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
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/nc/netcat.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
index cf8a87d8836..ba7e88af554 100644
--- a/usr.bin/nc/netcat.c
+++ b/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.153 2016/06/02 04:26:32 beck Exp $ */
+/* $OpenBSD: netcat.c,v 1.154 2016/06/27 23:58:08 deraadt Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
* Copyright (c) 2015 Bob Beck. All rights reserved.
@@ -144,7 +144,7 @@ struct tls *tls_setup_server(struct tls *, int, char *);
int
main(int argc, char *argv[])
{
- int ch, s, ret, socksv;
+ int ch, s = -1, ret, socksv;
char *host, *uport;
struct addrinfo hints;
struct servent *sv;
@@ -158,7 +158,6 @@ main(int argc, char *argv[])
struct tls *tls_ctx = NULL;
ret = 1;
- s = 0;
socksv = 5;
host = NULL;
uport = NULL;
@@ -586,8 +585,8 @@ main(int argc, char *argv[])
build_ports(uport);
/* Cycle through portlist, connecting to each port. */
- for (i = 0; portlist[i] != NULL; i++) {
- if (s)
+ for (s = -1, i = 0; portlist[i] != NULL; i++) {
+ if (s != -1)
close(s);
if (usetls) {
@@ -604,7 +603,7 @@ main(int argc, char *argv[])
else
s = remote_connect(host, portlist[i], hints);
- if (s < 0)
+ if (s == -1)
continue;
ret = 0;
@@ -653,7 +652,7 @@ main(int argc, char *argv[])
}
}
- if (s)
+ if (s != -1)
close(s);
tls_config_free(tls_cfg);