[Bug 191586] FreeBSD doesn't validate negative edgecases in bind(2)/connect(2)/listen(2) like POSIX requires

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sat Jul 12 16:39:02 UTC 2014


--- Comment #9 from Kevin Lo <kevlo at FreeBSD.org> ---
Hi Terry,

As you suggested, I asked Vincent Lubet how Mac OS X validates EAFNOSUPPORT
in bind(2).  Here is his response. 

"xnu version of bind() does not check the address family for AF_INET sockets 
 for compatibility with older program -- that's a piece of code we inherited 
 from FreeBSD!

 I do not have access to the POSIX test suite code but as Mac OS X was 
 granted conformance I have to assume the POSIX test suite for bind()
 does not test for bogus address family for AF_INET sockets. May be they
 only test for AF_UNIX."

Since Mac OS X was granted POSIX conformance, it makes more sense to me
to validate EAFNOSUPPORT in bind(2) for AF_UNIX only.
I think connect(2) should also return EAFNOSUPPORT for AF_UNIX on wrong
address family.

Here is the proposed patch, thanks

Index: sys/kern/uipc_usrreq.c
--- sys/kern/uipc_usrreq.c    (revision 268570)
+++ sys/kern/uipc_usrreq.c    (working copy)
@@ -467,6 +467,9 @@ uipc_bindat(int fd, struct socket *so, struct sock
     cap_rights_t rights;
     char *buf;

+    if (nam->sa_family != AF_UNIX)
+        return (EAFNOSUPPORT);
     unp = sotounpcb(so);
     KASSERT(unp != NULL, ("uipc_bind: unp == NULL"));

@@ -1278,6 +1281,9 @@ unp_connectat(int fd, struct socket *so, struct so
     cap_rights_t rights;
     int error, len;

+    if (nam->sa_family != AF_UNIX)
+        return (EAFNOSUPPORT);

     unp = sotounpcb(so);

You are receiving this mail because:
You are the assignee for the bug.

More information about the freebsd-standards mailing list