diff mbox

net: change recvform to return same address length as getsockname on unnamed unix sockets

Message ID v2x7447a0ac1004212029qd1866eaekc769fee5b13ac09d@mail.gmail.com
State Rejected, archived
Delegated to: David Miller
Headers show

Commit Message

Pavel Pergamenshchik April 22, 2010, 3:29 a.m. UTC
unix_*_recvmsg() returns zero-length sockaddr if the sender is an
unnamed AF_UNIX socket. Change it to return a two-byte sockaddr with
just the address family, to be consistent with unix_getname().

Signed-off-by: Pavel Pergamenshchik <ppergame@gmail.com>

---
Minimal example at http://xzrq.net/uaddrwtf.c
Solaris/OS X print 16 and 16. Linux prints 0 and 2 as described above.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

David Miller April 22, 2010, 5:26 a.m. UTC | #1
From: Pavel Pergamenshchik <ppergame@gmail.com>
Date: Wed, 21 Apr 2010 20:29:25 -0700

> unix_*_recvmsg() returns zero-length sockaddr if the sender is an
> unnamed AF_UNIX socket. Change it to return a two-byte sockaddr with
> just the address family, to be consistent with unix_getname().
> 
> Signed-off-by: Pavel Pergamenshchik <ppergame@gmail.com>

Since we've behaved this way for at least 10 years, the existing
behavior is the user visible ABI and the risk of breaking things by
making the change is too great.

I'm not applying this, sorry.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- a/net/unix/af_unix.c	2010-04-01 16:02:33.000000000 -0700
+++ b/net/unix/af_unix.c	2010-04-21 20:17:43.564703748 -0700
@@ -1634,9 +1634,13 @@ 
 static void unix_copy_addr(struct msghdr *msg, struct sock *sk)
 {
 	struct unix_sock *u = unix_sk(sk);
+	struct sockaddr_un *sunaddr;

-	msg->msg_namelen = 0;
-	if (u->addr) {
+	if (!u->addr) {
+		msg->msg_namelen = sizeof(short);
+		sunaddr = msg->msg_name;
+		sunaddr->sun_family = AF_UNIX;
+	} else {
 		msg->msg_namelen = u->addr->len;
 		memcpy(msg->msg_name, u->addr->name, u->addr->len);
 	}