From 42efad6ca3ee4fa561e93c2065fa3a45fbafde35 Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 18 Dec 2022 12:51:10 +0000 Subject: [PATCH] nc: do not test the connection in non-interactive mode The connection test writes four X to the socket, which corrupts data that we may want to pipe into nc. So don't do that if stdin is not a tty but still do it in scan mode, this is needed according to chris. based on a diff by and ok mpf --- usr.bin/nc/netcat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index e945ba6e8f0..dc60158749b 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.222 2022/12/18 12:48:28 tb Exp $ */ +/* $OpenBSD: netcat.c,v 1.223 2022/12/18 12:51:10 tb Exp $ */ /* * Copyright (c) 2001 Eric Jackson * Copyright (c) 2015 Bob Beck. All rights reserved. @@ -1510,6 +1510,10 @@ udptest(int s) { int i, ret; + /* Only write to the socket in scan mode or interactive mode. */ + if (!zflag && !isatty(STDIN_FILENO)) + return 0; + for (i = 0; i <= 3; i++) { if (write(s, "X", 1) == 1) ret = 1; -- 2.20.1