diff options
| author | bluhm <> | 2018-09-06 13:23:02 +0000 |
|---|---|---|
| committer | bluhm <> | 2018-09-06 13:23:02 +0000 |
| commit | 5439125a3e68735691ddd4e73d81f9f9b7c2c2ac (patch) | |
| tree | 835337dbd9bee58d4ce791eaae9e783b08292064 /src | |
| parent | 4e47c515f40e5440374f3cb833834c52edfd8b18 (diff) | |
| download | openbsd-5439125a3e68735691ddd4e73d81f9f9b7c2c2ac.tar.gz openbsd-5439125a3e68735691ddd4e73d81f9f9b7c2c2ac.tar.bz2 openbsd-5439125a3e68735691ddd4e73d81f9f9b7c2c2ac.zip | |
Do not close the socket twice in netcat.
from Nan Xiao; OK tb@
Diffstat (limited to 'src')
| -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 | } |
