Module Name:    src
Committed By:   snj
Date:           Thu Jun 15 05:32:35 UTC 2017

Modified Files:
        src/sys/netcan [netbsd-8]: can_pcb.c
        src/tests/net/can [netbsd-8]: t_can.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.5.2.1 src/sys/netcan/can_pcb.c
cvs rdiff -u -r1.5 -r1.5.2.1 src/tests/net/can/t_can.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netcan/can_pcb.c
diff -u src/sys/netcan/can_pcb.c:1.5 src/sys/netcan/can_pcb.c:1.5.2.1
--- src/sys/netcan/can_pcb.c:1.5	Thu Jun  1 02:45:14 2017
+++ src/sys/netcan/can_pcb.c	Thu Jun 15 05:32:35 2017
@@ -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 @@ can_pcbbind(void *v, struct sockaddr_can
 	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;

Index: src/tests/net/can/t_can.c
diff -u src/tests/net/can/t_can.c:1.5 src/tests/net/can/t_can.c:1.5.2.1
--- src/tests/net/can/t_can.c:1.5	Sun May 28 14:53:13 2017
+++ src/tests/net/can/t_can.c	Thu Jun 15 05:32:35 2017
@@ -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_BODY(cannoloop, tc)
 	}
 }
 
+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_TCS(tp)
         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();
 }

Reply via email to