Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern make soconnect() fail with EAFNOSUPPORT if the doma...



details:   https://anonhg.NetBSD.org/src/rev/bcb7a76f2180
branches:  trunk
changeset: 337895:bcb7a76f2180
user:      rtr <rtr%NetBSD.org@localhost>
date:      Sat May 02 20:10:26 2015 +0000

description:
make soconnect() fail with EAFNOSUPPORT if the domain of the socket does
not match family received in the sockaddr.

* connect() now fails as documented in connect(2).
* atf test t_connect:connect_foreign_family now passes.

diffstat:

 sys/kern/uipc_socket.c |  13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diffs (36 lines):

diff -r f75028a29d93 -r bcb7a76f2180 sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Sat May 02 18:18:13 2015 +0000
+++ b/sys/kern/uipc_socket.c    Sat May 02 20:10:26 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket.c,v 1.240 2015/05/02 17:18:03 rtr Exp $    */
+/*     $NetBSD: uipc_socket.c,v 1.241 2015/05/02 20:10:26 rtr Exp $    */
 
 /*-
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.240 2015/05/02 17:18:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.241 2015/05/02 20:10:26 rtr Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_sock_counters.h"
@@ -827,10 +827,15 @@
         */
        if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) &&
            ((so->so_proto->pr_flags & PR_CONNREQUIRED) ||
-           (error = sodisconnect(so))))
+           (error = sodisconnect(so)))) {
                error = EISCONN;
-       else
+       } else {
+               if (NULL != nam &&
+                   nam->sa_family != so->so_proto->pr_domain->dom_family) {
+                       return EAFNOSUPPORT;
+               }
                error = (*so->so_proto->pr_usrreqs->pr_connect)(so, nam, l);
+       }
 
        return error;
 }



Home | Main Index | Thread Index | Old Index