Subject: Re: if_attach problem
To: None <managgarwal@hss.hns.com>
From: Matthias Drochner <M.Drochner@fz-juelich.de>
List: tech-kern
Date: 11/20/2003 16:08:04
This is a multipart MIME message.

--==_Exmh_8871522348720
Content-Type: text/plain; charset=us-ascii


managgarwal@hss.hns.com said:
> --> crash occurs at line "while (ifindex2ifnet[ifp->if_index] != NULL)
> { " when ifp->if_index value is 1024 and total number of records
> malloc are 1024.. 

This is fixed in -current; I've just submitted a pullup request
for the 1.6 branch.
I'll append the patch in case you want to try.

best regards
Matthias



--==_Exmh_8871522348720
Content-Type: text/plain ; name="d1"; charset=us-ascii
Content-Description: d1
Content-Disposition: attachment; filename="d1"

Index: if.c
===================================================================
RCS file: /cvsroot/src/sys/net/if.c,v
retrieving revision 1.104.4.3
diff -u -r1.104.4.3 if.c
--- if.c	10 Sep 2003 19:00:09 -0000	1.104.4.3
+++ if.c	20 Nov 2003 14:23:31 -0000
@@ -370,7 +370,8 @@
 	if (ifindex2ifnet == 0)
 		if_index++;
 	else
-		while (ifindex2ifnet[ifp->if_index] != NULL) {
+		while (ifp->if_index < if_indexlim &&
+		    ifindex2ifnet[ifp->if_index] != NULL) {
 			++if_index;
 			if (if_index == 0)
 				if_index = 1;
@@ -405,28 +406,31 @@
 	 */
 	if (ifnet_addrs == 0 || ifindex2ifnet == 0 ||
 	    ifp->if_index >= if_indexlim) {
-		size_t n;
+		size_t m, n, oldlim;
 		caddr_t q;
 		
+		oldlim = if_indexlim;
 		while (ifp->if_index >= if_indexlim)
 			if_indexlim <<= 1;
 
 		/* grow ifnet_addrs */
+		m = oldlim * sizeof(struct ifaddr *);
 		n = if_indexlim * sizeof(struct ifaddr *);
 		q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
 		memset(q, 0, n);
 		if (ifnet_addrs) {
-			bcopy((caddr_t)ifnet_addrs, q, n/2);
+			bcopy((caddr_t)ifnet_addrs, q, m);
 			free((caddr_t)ifnet_addrs, M_IFADDR);
 		}
 		ifnet_addrs = (struct ifaddr **)q;
 
 		/* grow ifindex2ifnet */
+		m = oldlim * sizeof(struct ifnet *);
 		n = if_indexlim * sizeof(struct ifnet *);
 		q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
 		memset(q, 0, n);
 		if (ifindex2ifnet) {
-			bcopy((caddr_t)ifindex2ifnet, q, n/2);
+			bcopy((caddr_t)ifindex2ifnet, q, m);
 			free((caddr_t)ifindex2ifnet, M_IFADDR);
 		}
 		ifindex2ifnet = (struct ifnet **)q;

--==_Exmh_8871522348720--