If the control message of IP_SENDSRCADDR did not fit into the socket
authorbluhm <bluhm@openbsd.org>
Tue, 21 Aug 2018 12:34:11 +0000 (12:34 +0000)
committerbluhm <bluhm@openbsd.org>
Tue, 21 Aug 2018 12:34:11 +0000 (12:34 +0000)
buffer together with an UDP packet, sosend(9) returned EWOULDBLOCK.
As it is an persistent problem, EMSGSIZE is the correct error code.
Split the AF_UNIX case into a separate condition and do not change
its logic.  For atomic protocols, check that both data and control
message length fit into the socket buffer.
original bug report from Alexander Markert
discussed with jca@; OK vgross@

sys/kern/uipc_socket.c

index f3806dc..d50b6dd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uipc_socket.c,v 1.226 2018/07/30 12:22:14 mpi Exp $   */
+/*     $OpenBSD: uipc_socket.c,v 1.227 2018/08/21 12:34:11 bluhm Exp $ */
 /*     $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $        */
 
 /*
@@ -462,10 +462,14 @@ restart:
                space = sbspace(so, &so->so_snd);
                if (flags & MSG_OOB)
                        space += 1024;
-               if ((atomic && resid > so->so_snd.sb_hiwat) ||
-                   (so->so_proto->pr_domain->dom_family != AF_UNIX &&
-                   clen > so->so_snd.sb_hiwat))
-                       snderr(EMSGSIZE);
+               if (so->so_proto->pr_domain->dom_family == AF_UNIX) {
+                       if (atomic && resid > so->so_snd.sb_hiwat)
+                               snderr(EMSGSIZE);
+               } else {
+                       if (clen > so->so_snd.sb_hiwat ||
+                           (atomic && resid > so->so_snd.sb_hiwat - clen))
+                               snderr(EMSGSIZE);
+               }
                if (space < clen ||
                    (space - clen < resid &&
                    (atomic || space < so->so_snd.sb_lowat))) {