From 4b5f7ec676379255496a2e84d8916b76ab07f086 Mon Sep 17 00:00:00 2001 From: bluhm <> Date: Wed, 8 Feb 2017 18:03:31 +0000 Subject: 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@ --- src/usr.bin/nc/netcat.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src') 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 @@ -/* $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 * 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) -- cgit v1.2.3-55-g6feb