summaryrefslogtreecommitdiff
path: root/usr.bin/nc/netcat.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2017-02-08 18:03:32 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2017-02-08 18:03:32 +0000
commit60af51dd241d16df91ad37ea515ceda03ed1ec5f (patch)
treefc068d31947f7ca9665aa63dae26e8c175aada90 /usr.bin/nc/netcat.c
parent48b54bcc0d4893b10741670656ea0896c172cedf (diff)
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 'usr.bin/nc/netcat.c')
-rw-r--r--usr.bin/nc/netcat.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
index 8984e8f3035..cabb3ceea6c 100644
--- a/usr.bin/nc/netcat.c
+++ b/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.173 2017/02/08 13:43:33 bluhm Exp $ */
+/* $OpenBSD: netcat.c,v 1.174 2017/02/08 18:03:31 bluhm Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
* Copyright (c) 2015 Bob Beck. All rights reserved.
@@ -1047,21 +1047,15 @@ readwrite(int net_fd, struct tls *tls_ctx)
while (1) {
/* both inputs are gone, buffers are empty, we are done */
if (pfd[POLL_STDIN].fd == -1 && pfd[POLL_NETIN].fd == -1 &&
- stdinbufpos == 0 && netinbufpos == 0) {
- close(net_fd);
+ stdinbufpos == 0 && netinbufpos == 0)
return;
- }
/* both outputs are gone, we can't continue */
- if (pfd[POLL_NETOUT].fd == -1 && pfd[POLL_STDOUT].fd == -1) {
- close(net_fd);
+ if (pfd[POLL_NETOUT].fd == -1 && pfd[POLL_STDOUT].fd == -1)
return;
- }
/* listen and net in gone, queues empty, done */
if (lflag && pfd[POLL_NETIN].fd == -1 &&
- stdinbufpos == 0 && netinbufpos == 0) {
- close(net_fd);
+ stdinbufpos == 0 && netinbufpos == 0)
return;
- }
/* help says -i is for "wait between lines sent". We read and
* write arbitrary amounts of data, and we don't want to start
@@ -1073,10 +1067,8 @@ readwrite(int net_fd, struct tls *tls_ctx)
num_fds = poll(pfd, 4, timeout);
/* treat poll errors */
- if (num_fds == -1) {
- close(net_fd);
+ if (num_fds == -1)
err(1, "polling error");
- }
/* timeout happened */
if (num_fds == 0)