diff options
author | bluhm <> | 2018-09-06 13:23:02 +0000 |
---|---|---|
committer | bluhm <> | 2018-09-06 13:23:02 +0000 |
commit | a267c63d946b543a11f0afc79e6a96b027035b7c (patch) | |
tree | 835337dbd9bee58d4ce791eaae9e783b08292064 /src/usr.bin/nc/netcat.c | |
parent | de40edcfdbe61b35779d4d9d364860a212cf755a (diff) | |
download | openbsd-a267c63d946b543a11f0afc79e6a96b027035b7c.tar.gz openbsd-a267c63d946b543a11f0afc79e6a96b027035b7c.tar.bz2 openbsd-a267c63d946b543a11f0afc79e6a96b027035b7c.zip |
Do not close the socket twice in netcat.
from Nan Xiao; OK tb@
Diffstat (limited to 'src/usr.bin/nc/netcat.c')
-rw-r--r-- | src/usr.bin/nc/netcat.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 8e7f7e1718..e02ddd6336 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.192 2018/08/10 17:15:22 deraadt Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.193 2018/09/06 13:23:02 bluhm 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. |
@@ -564,8 +564,11 @@ main(int argc, char *argv[]) | |||
564 | } | 564 | } |
565 | /* Allow only one connection at a time, but stay alive. */ | 565 | /* Allow only one connection at a time, but stay alive. */ |
566 | for (;;) { | 566 | for (;;) { |
567 | if (family != AF_UNIX) | 567 | if (family != AF_UNIX) { |
568 | if (s != -1) | ||
569 | close(s); | ||
568 | s = local_listen(host, uport, hints); | 570 | s = local_listen(host, uport, hints); |
571 | } | ||
569 | if (s < 0) | 572 | if (s < 0) |
570 | err(1, NULL); | 573 | err(1, NULL); |
571 | if (uflag && kflag) { | 574 | if (uflag && kflag) { |
@@ -622,9 +625,7 @@ main(int argc, char *argv[]) | |||
622 | } | 625 | } |
623 | close(connfd); | 626 | close(connfd); |
624 | } | 627 | } |
625 | if (family != AF_UNIX) | 628 | if (family == AF_UNIX && uflag) { |
626 | close(s); | ||
627 | else if (uflag) { | ||
628 | if (connect(s, NULL, 0) < 0) | 629 | if (connect(s, NULL, 0) < 0) |
629 | err(1, "connect"); | 630 | err(1, "connect"); |
630 | } | 631 | } |