From de54d280eb9fe4604c05c8956adc9d9dce4a7309 Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Tue, 6 Oct 2020 09:06:10 -0400 Subject: [PATCH] Cygwin: AF_UNIX: sendmsg: handle messages that are too long Return with errno EMSGSIZE if AF_UNIX_PKT_DATA_APPEND fails before any data has been added to the packet to be sent. --- winsup/cygwin/fhandler_socket_unix.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc index 30009500c..f6f1db82d 100644 --- a/winsup/cygwin/fhandler_socket_unix.cc +++ b/winsup/cygwin/fhandler_socket_unix.cc @@ -2053,7 +2053,15 @@ fhandler_socket_unix::sendmsg (const struct msghdr *msg, int flags) for (int i = 0; i < msg->msg_iovlen; ++i) if (!AF_UNIX_PKT_DATA_APPEND (packet, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len)) - break; + { + if (packet->data_len == 0) + { + set_errno (EMSGSIZE); + __leave; + } + else + break; + } io_lock (); /* Handle MSG_DONTWAIT in blocking mode */ if (!is_nonblocking () && (flags & MSG_DONTWAIT))