aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2021-01-26 18:50:50 -0600
committerRob Landley <rob@landley.net>2021-01-26 18:50:50 -0600
commit2b4abd05efcc96061eaa87a6fdbc3f7121fd2c08 (patch)
tree5b2a372b400388ad7446d71aff9310299060f16f
parent76d3160cfabe15568f006ad530c105b9ad6fdcdd (diff)
downloadtoybox-2b4abd05efcc96061eaa87a6fdbc3f7121fd2c08.tar.gz
Fix bug pointed out by asm89 and add test.
-rw-r--r--lib/net.c5
-rwxr-xr-xtests/netcat.test11
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/net.c b/lib/net.c
index 02354444..414c82a5 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -114,7 +114,10 @@ int pollinate(int in1, int in2, int out1, int out2, int timeout, int shutdown_ti
if (pollfds[i].revents & POLLIN) {
int len = read(pollfds[i].fd, libbuf, sizeof(libbuf));
if (len<1) pollfds[i].revents = POLLHUP;
- else xwrite(i ? out2 : out1, libbuf, len);
+ else {
+ xwrite(i ? out2 : out1, libbuf, len);
+ continue;
+ }
}
if (pollfds[i].revents & POLLHUP) {
// Close half-connection. This is needed for things like
diff --git a/tests/netcat.test b/tests/netcat.test
new file mode 100755
index 00000000..40b51d40
--- /dev/null
+++ b/tests/netcat.test
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+{ dd if=/dev/zero bs=4k count=1 2>/dev/null | tr '\0' a; echo b; } > testfile
+testing "more than buffer bytes left at end" \
+ "netcat -lp 1234 wc -c & cat testfile | netcat 127.0.0.1 1234" \
+ "4098\n" "" ""
+rm -f testfile