Module Name:    src
Committed By:   bouyer
Date:           Fri Jun  9 08:21:41 UTC 2017

Modified Files:
        src/sys/netcan: can_pcb.c

Log Message:
Refuse to bind to a non-CAN interface.
Also release the lock in the error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/netcan/can_pcb.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.6
--- src/sys/netcan/can_pcb.c:1.5	Thu Jun  1 02:45:14 2017
+++ src/sys/netcan/can_pcb.c	Fri Jun  9 08:21:41 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.6 2017/06/09 08:21:41 bouyer 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.6 2017/06/09 08:21:41 bouyer 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;

Reply via email to