summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobias <>2015-03-26 10:36:03 +0000
committertobias <>2015-03-26 10:36:03 +0000
commitc7f9562c6817ff9e8173bdc36298349d8bf028c4 (patch)
tree2fbd12acce639dacf64e0f60017e5d433f3e1748
parent6b3df1611baaef2402727623bbbd118e85c195ac (diff)
downloadopenbsd-c7f9562c6817ff9e8173bdc36298349d8bf028c4.tar.gz
openbsd-c7f9562c6817ff9e8173bdc36298349d8bf028c4.tar.bz2
openbsd-c7f9562c6817ff9e8173bdc36298349d8bf028c4.zip
Check for short writes in fdpass(). Clean up while at it.
ok djm
-rw-r--r--src/usr.bin/nc/netcat.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index ce7fde4525..88a2a25053 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.127 2015/02/14 22:40:22 jca Exp $ */ 1/* $OpenBSD: netcat.c,v 1.128 2015/03/26 10:36:03 tobias Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -980,7 +980,6 @@ fdpass(int nfd)
980 bzero(&mh, sizeof(mh)); 980 bzero(&mh, sizeof(mh));
981 bzero(&cmsgbuf, sizeof(cmsgbuf)); 981 bzero(&cmsgbuf, sizeof(cmsgbuf));
982 bzero(&iov, sizeof(iov)); 982 bzero(&iov, sizeof(iov));
983 bzero(&pfd, sizeof(pfd));
984 983
985 mh.msg_control = (caddr_t)&cmsgbuf.buf; 984 mh.msg_control = (caddr_t)&cmsgbuf.buf;
986 mh.msg_controllen = sizeof(cmsgbuf.buf); 985 mh.msg_controllen = sizeof(cmsgbuf.buf);
@@ -997,17 +996,17 @@ fdpass(int nfd)
997 996
998 bzero(&pfd, sizeof(pfd)); 997 bzero(&pfd, sizeof(pfd));
999 pfd.fd = STDOUT_FILENO; 998 pfd.fd = STDOUT_FILENO;
999 pfd.events = POLLOUT;
1000 for (;;) { 1000 for (;;) {
1001 r = sendmsg(STDOUT_FILENO, &mh, 0); 1001 r = sendmsg(STDOUT_FILENO, &mh, 0);
1002 if (r == -1) { 1002 if (r == -1) {
1003 if (errno == EAGAIN || errno == EINTR) { 1003 if (errno == EAGAIN || errno == EINTR) {
1004 pfd.events = POLLOUT;
1005 if (poll(&pfd, 1, -1) == -1) 1004 if (poll(&pfd, 1, -1) == -1)
1006 err(1, "poll"); 1005 err(1, "poll");
1007 continue; 1006 continue;
1008 } 1007 }
1009 err(1, "sendmsg"); 1008 err(1, "sendmsg");
1010 } else if (r == -1) 1009 } else if (r != 1)
1011 errx(1, "sendmsg: unexpected return value %zd", r); 1010 errx(1, "sendmsg: unexpected return value %zd", r);
1012 else 1011 else
1013 break; 1012 break;