diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2003-10-01 05:06:07 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2003-10-01 05:06:07 +0000 |
commit | cd41006fd50978e67255469957b7d46f0de70909 (patch) | |
tree | d7549fb9eb2ed43d224c187ad6e0de737fcf9bb3 /sys/net/if.c | |
parent | d474ccfc0f98185db0357693261b69c02c077f7f (diff) |
make ifindex2ifnet growing code more correct. (found by iij seil team)
Diffstat (limited to 'sys/net/if.c')
-rw-r--r-- | sys/net/if.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index ba44bcec1aa..451d530d1da 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.70 2003/08/27 00:33:34 henric Exp $ */ +/* $OpenBSD: if.c,v 1.71 2003/10/01 05:06:06 itojun Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -160,28 +160,31 @@ if_attachsetup(ifp) * struct ifnet **ifindex2ifnet */ if (ifnet_addrs == 0 || ifindex2ifnet == 0 || if_index >= if_indexlim) { - size_t n; + size_t m, n, oldlim; caddr_t q; + oldlim = if_indexlim; while (if_index >= if_indexlim) if_indexlim <<= 1; /* grow ifnet_addrs */ + m = oldlim * sizeof(ifa); n = if_indexlim * sizeof(ifa); q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK); bzero(q, 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); bzero(q, 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; |