summaryrefslogtreecommitdiff
path: root/src/usr.bin/nc/netcat.c
diff options
context:
space:
mode:
authorbeck <>2019-10-17 14:29:24 +0000
committerbeck <>2019-10-17 14:29:24 +0000
commitf94e8cb1dd847cd2efa0211e711707fc705f11eb (patch)
treed8e00c33ebebf863ba58ad8bb0da909a856c882b /src/usr.bin/nc/netcat.c
parentfd5ddb2c2c8843a96f8b820d67e8fdd3652584f2 (diff)
downloadopenbsd-f94e8cb1dd847cd2efa0211e711707fc705f11eb.tar.gz
openbsd-f94e8cb1dd847cd2efa0211e711707fc705f11eb.tar.bz2
openbsd-f94e8cb1dd847cd2efa0211e711707fc705f11eb.zip
Fix -N flag to actually shut down the (entire) socket when the input
goes away. This allows for using nc in cases where the network server will no longer expect anything after eof, instead of hanging waiting for more input from our end. Additionaly, shut down if tls is in use if either side of the socket goes away, since we higher level TLS operations (tls_read and write) will require the socket to be both readable and writable as we can get TLS_WANT_POLLIN or TLS_WANT_POLLOUT on either operation. deraadt@ buying it. found by sthen@
Diffstat (limited to 'src/usr.bin/nc/netcat.c')
-rw-r--r--src/usr.bin/nc/netcat.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index c04298f64c..795592f0b7 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.206 2019/08/08 16:49:35 mestre Exp $ */ 1/* $OpenBSD: netcat.c,v 1.207 2019/10/17 14:29:24 beck 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.
@@ -1259,6 +1259,23 @@ readwrite(int net_fd, struct tls *tls_ctx)
1259 if (pfd[POLL_NETIN].fd == -1 && netinbufpos == 0) { 1259 if (pfd[POLL_NETIN].fd == -1 && netinbufpos == 0) {
1260 pfd[POLL_STDOUT].fd = -1; 1260 pfd[POLL_STDOUT].fd = -1;
1261 } 1261 }
1262
1263 if (((usetls || Nflag) && (pfd[POLL_NETIN].fd == -1)) ||
1264 (usetls && pfd[POLL_NETOUT].fd == -1)) {
1265 /*
1266 * -N says: shutdown(2) the 'network socket'
1267 * after EOF on the input
1268 *
1269 * for TLS we need to die if either end is
1270 * toast, since both reading and writing to
1271 * the socket may be necessary for any higher
1272 * level tls operation
1273 */
1274 shutdown(pfd[POLL_NETOUT].fd, SHUT_WR);
1275 shutdown(pfd[POLL_NETIN].fd, SHUT_RD);
1276 pfd[POLL_NETOUT].fd = -1;
1277 pfd[POLL_NETIN].fd = -1;
1278 }
1262 } 1279 }
1263} 1280}
1264 1281