Source-Changes-HG archive

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

[src/netbsd-8]: src Pull up following revision(s) (requested by bouyer in tic...



details:   https://anonhg.NetBSD.org/src/rev/596820e2c235
branches:  netbsd-8
changeset: 850730:596820e2c235
user:      snj <snj%NetBSD.org@localhost>
date:      Thu Jun 15 05:32:35 2017 +0000

description:
Pull up following revision(s) (requested by bouyer in ticket #34):
        sys/netcan/can_pcb.c: revision 1.6
        tests/net/can/t_can.c: revision 1.6
Refuse to bind to a non-CAN interface.
Also release the lock in the error branch.
--
Test bind()ing to a non-existent interface.

diffstat:

 sys/netcan/can_pcb.c  |  10 +++++++---
 tests/net/can/t_can.c |  30 ++++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 5 deletions(-)

diffs (89 lines):

diff -r e6f209aced7e -r 596820e2c235 sys/netcan/can_pcb.c
--- a/sys/netcan/can_pcb.c      Thu Jun 15 05:30:13 2017 +0000
+++ b/sys/netcan/can_pcb.c      Thu Jun 15 05:32:35 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: can_pcb.c,v 1.5 2017/06/01 02:45:14 chs Exp $  */
+/*     $NetBSD: can_pcb.c,v 1.5.2.1 2017/06/15 05:32:35 snj Exp $      */
 
 /*-
  * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: can_pcb.c,v 1.5 2017/06/01 02:45:14 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: can_pcb.c,v 1.5.2.1 2017/06/15 05:32:35 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -127,8 +127,12 @@
        mutex_enter(&canp->canp_mtx);
        if (scan->can_ifindex != 0) {
                canp->canp_ifp = if_byindex(scan->can_ifindex);
-               if (canp->canp_ifp == NULL)
+               if (canp->canp_ifp == NULL ||
+                   canp->canp_ifp->if_dlt != DLT_CAN_SOCKETCAN) {
+                       canp->canp_ifp = NULL;
+                       mutex_exit(&canp->canp_mtx);
                        return (EADDRNOTAVAIL);
+               }
                soisconnected(canp->canp_socket);
        } else {
                canp->canp_ifp = NULL;
diff -r e6f209aced7e -r 596820e2c235 tests/net/can/t_can.c
--- a/tests/net/can/t_can.c     Thu Jun 15 05:30:13 2017 +0000
+++ b/tests/net/can/t_can.c     Thu Jun 15 05:32:35 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_can.c,v 1.5 2017/05/28 14:53:13 christos Exp $       */
+/*     $NetBSD: t_can.c,v 1.5.2.1 2017/06/15 05:32:35 snj Exp $        */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: t_can.c,v 1.5 2017/05/28 14:53:13 christos Exp $");
+__RCSID("$NetBSD: t_can.c,v 1.5.2.1 2017/06/15 05:32:35 snj Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -717,6 +717,31 @@
        }
 }
 
+ATF_TC(canbindunknown);
+ATF_TC_HEAD(canbindunknown, tc)
+{
+
+       atf_tc_set_md_var(tc, "descr", "check that bind to unkown interface fails");
+       atf_tc_set_md_var(tc, "timeout", "5");
+}
+
+ATF_TC_BODY(canbindunknown, tc)
+{
+       struct sockaddr_can sa;
+       int r, s;
+
+       rump_init();
+
+       s = can_socket_with_own();
+
+       sa.can_family = AF_CAN;
+       sa.can_ifindex = 10; /* should not exist */
+
+       r = rump_sys_bind(s, (struct sockaddr *)&sa, sizeof(sa));
+
+       ATF_CHECK_MSG(r < 0, "bind() didn't fail (%d)", r);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -730,5 +755,6 @@
         ATF_TP_ADD_TC(tp, canrecvfrom);
         ATF_TP_ADD_TC(tp, canbindfilter);
         ATF_TP_ADD_TC(tp, cannoloop);
+        ATF_TP_ADD_TC(tp, canbindunknown);
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index