diff options
| author | bluhm <> | 2017-02-08 18:03:31 +0000 |
|---|---|---|
| committer | bluhm <> | 2017-02-08 18:03:31 +0000 |
| commit | a94b7f932785504243453f5af199073e401a6650 (patch) | |
| tree | d8d09e148aceffc0b7a5275439576fbc41cdd631 /src | |
| parent | 22da9b1ce9d2622c9f1e478e15393cf54e1395fb (diff) | |
| download | openbsd-a94b7f932785504243453f5af199073e401a6650.tar.gz openbsd-a94b7f932785504243453f5af199073e401a6650.tar.bz2 openbsd-a94b7f932785504243453f5af199073e401a6650.zip | |
Avoid double close(2) in netcat. After every call to readwrite()
there is already a close(2), so do not do it in readwrite().
OK beck@
Diffstat (limited to 'src')
| -rw-r--r-- | src/usr.bin/nc/netcat.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 8984e8f303..cabb3ceea6 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.173 2017/02/08 13:43:33 bluhm Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.174 2017/02/08 18:03:31 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. |
| @@ -1047,21 +1047,15 @@ readwrite(int net_fd, struct tls *tls_ctx) | |||
| 1047 | while (1) { | 1047 | while (1) { |
| 1048 | /* both inputs are gone, buffers are empty, we are done */ | 1048 | /* both inputs are gone, buffers are empty, we are done */ |
| 1049 | if (pfd[POLL_STDIN].fd == -1 && pfd[POLL_NETIN].fd == -1 && | 1049 | if (pfd[POLL_STDIN].fd == -1 && pfd[POLL_NETIN].fd == -1 && |
| 1050 | stdinbufpos == 0 && netinbufpos == 0) { | 1050 | stdinbufpos == 0 && netinbufpos == 0) |
| 1051 | close(net_fd); | ||
| 1052 | return; | 1051 | return; |
| 1053 | } | ||
| 1054 | /* both outputs are gone, we can't continue */ | 1052 | /* both outputs are gone, we can't continue */ |
| 1055 | if (pfd[POLL_NETOUT].fd == -1 && pfd[POLL_STDOUT].fd == -1) { | 1053 | if (pfd[POLL_NETOUT].fd == -1 && pfd[POLL_STDOUT].fd == -1) |
| 1056 | close(net_fd); | ||
| 1057 | return; | 1054 | return; |
| 1058 | } | ||
| 1059 | /* listen and net in gone, queues empty, done */ | 1055 | /* listen and net in gone, queues empty, done */ |
| 1060 | if (lflag && pfd[POLL_NETIN].fd == -1 && | 1056 | if (lflag && pfd[POLL_NETIN].fd == -1 && |
| 1061 | stdinbufpos == 0 && netinbufpos == 0) { | 1057 | stdinbufpos == 0 && netinbufpos == 0) |
| 1062 | close(net_fd); | ||
| 1063 | return; | 1058 | return; |
| 1064 | } | ||
| 1065 | 1059 | ||
| 1066 | /* help says -i is for "wait between lines sent". We read and | 1060 | /* help says -i is for "wait between lines sent". We read and |
| 1067 | * write arbitrary amounts of data, and we don't want to start | 1061 | * write arbitrary amounts of data, and we don't want to start |
| @@ -1073,10 +1067,8 @@ readwrite(int net_fd, struct tls *tls_ctx) | |||
| 1073 | num_fds = poll(pfd, 4, timeout); | 1067 | num_fds = poll(pfd, 4, timeout); |
| 1074 | 1068 | ||
| 1075 | /* treat poll errors */ | 1069 | /* treat poll errors */ |
| 1076 | if (num_fds == -1) { | 1070 | if (num_fds == -1) |
| 1077 | close(net_fd); | ||
| 1078 | err(1, "polling error"); | 1071 | err(1, "polling error"); |
| 1079 | } | ||
| 1080 | 1072 | ||
| 1081 | /* timeout happened */ | 1073 | /* timeout happened */ |
| 1082 | if (num_fds == 0) | 1074 | if (num_fds == 0) |
