diff options
author | 2019-06-10 16:32:51 +0000 | |
---|---|---|
committer | 2019-06-10 16:32:51 +0000 | |
commit | b82d192b5f65a9c7874e171ed8a92d692ac77073 (patch) | |
tree | 42cc6110bad462f674291150412b3fda035a1965 | |
parent | Use PWAIT instead of PUSER in tsleep(9). (diff) | |
download | wireguard-openbsd-b82d192b5f65a9c7874e171ed8a92d692ac77073.tar.xz wireguard-openbsd-b82d192b5f65a9c7874e171ed8a92d692ac77073.zip |
Use mallocarray(9) & put some free(9) sizes for M_IPMOPTS allocations.
ok semarie@, visa@
-rw-r--r-- | sys/net/if_pfsync.c | 10 | ||||
-rw-r--r-- | sys/net/if_vxlan.c | 10 | ||||
-rw-r--r-- | sys/netinet/ip_carp.c | 10 | ||||
-rw-r--r-- | sys/netinet/ip_output.c | 16 | ||||
-rw-r--r-- | sys/netinet6/ip6_output.c | 10 |
5 files changed, 27 insertions, 29 deletions
diff --git a/sys/net/if_pfsync.c b/sys/net/if_pfsync.c index 25ef5243824..fbfe28ea650 100644 --- a/sys/net/if_pfsync.c +++ b/sys/net/if_pfsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pfsync.c,v 1.263 2019/06/04 23:00:43 sashan Exp $ */ +/* $OpenBSD: if_pfsync.c,v 1.264 2019/06/10 16:32:51 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff @@ -328,9 +328,8 @@ pfsync_clone_create(struct if_clone *ifc, int unit) sc->sc_len = PFSYNC_MINPKT; sc->sc_maxupdates = 128; - sc->sc_imo.imo_membership = (struct in_multi **)malloc( - (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, - M_WAITOK | M_ZERO); + sc->sc_imo.imo_membership = mallocarray(IP_MIN_MEMBERSHIPS, + sizeof(struct in_multi *), M_IPMOPTS, M_WAITOK|M_ZERO); sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS; ifp = &sc->sc_if; @@ -407,7 +406,8 @@ pfsync_clone_destroy(struct ifnet *ifp) NET_UNLOCK(); pool_destroy(&sc->sc_pool); - free(sc->sc_imo.imo_membership, M_IPMOPTS, 0); + free(sc->sc_imo.imo_membership, M_IPMOPTS, + sc->sc_imo.imo_max_memberships * sizeof(struct in_multi *)); free(sc, M_DEVBUF, sizeof(*sc)); return (0); diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c index ca42e7f8a21..328af93cce7 100644 --- a/sys/net/if_vxlan.c +++ b/sys/net/if_vxlan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vxlan.c,v 1.72 2019/04/28 22:15:58 mpi Exp $ */ +/* $OpenBSD: if_vxlan.c,v 1.73 2019/06/10 16:32:51 mpi Exp $ */ /* * Copyright (c) 2013 Reyk Floeter <reyk@openbsd.org> @@ -131,9 +131,8 @@ vxlan_clone_create(struct if_clone *ifc, int unit) struct vxlan_softc *sc; sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); - sc->sc_imo.imo_membership = malloc( - (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, - M_WAITOK|M_ZERO); + sc->sc_imo.imo_membership = mallocarray(IP_MIN_MEMBERSHIPS, + sizeof(struct in_multi *), M_IPMOPTS, M_WAITOK|M_ZERO); sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS; sc->sc_dstport = htons(VXLAN_PORT); sc->sc_vnetid = VXLAN_VNI_UNSET; @@ -199,7 +198,8 @@ vxlan_clone_destroy(struct ifnet *ifp) if (!task_del(net_tq(ifp->if_index), &sc->sc_sendtask)) taskq_barrier(net_tq(ifp->if_index)); - free(sc->sc_imo.imo_membership, M_IPMOPTS, 0); + free(sc->sc_imo.imo_membership, M_IPMOPTS, + sc->sc_imo.imo_max_memberships * sizeof(struct in_multi *)); free(sc, M_DEVBUF, sizeof(*sc)); return (0); diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 8f6d59b3953..80ce7cb4b38 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.337 2019/04/23 10:53:45 dlg Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.338 2019/06/10 16:32:51 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -814,9 +814,8 @@ carp_clone_create(struct if_clone *ifc, int unit) #ifdef INET6 sc->sc_im6o.im6o_hlim = CARP_DFLTTL; #endif /* INET6 */ - sc->sc_imo.imo_membership = (struct in_multi **)malloc( - (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, - M_WAITOK|M_ZERO); + sc->sc_imo.imo_membership = mallocarray(IP_MIN_MEMBERSHIPS, + sizeof(struct in_multi *), M_IPMOPTS, M_WAITOK|M_ZERO); sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS; LIST_INIT(&sc->carp_mc_listhead); @@ -901,7 +900,8 @@ carp_clone_destroy(struct ifnet *ifp) if_detach(ifp); carp_destroy_vhosts(ifp->if_softc); refcnt_finalize(&sc->sc_refcnt, "carpdtor"); - free(sc->sc_imo.imo_membership, M_IPMOPTS, 0); + free(sc->sc_imo.imo_membership, M_IPMOPTS, + sc->sc_imo.imo_max_memberships * sizeof(struct in_multi *)); free(sc, M_DEVBUF, sizeof(*sc)); return (0); } diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index b69cebc5d0b..7bc8254d3de 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.354 2019/04/28 22:15:58 mpi Exp $ */ +/* $OpenBSD: ip_output.c,v 1.355 2019/06/10 16:32:51 mpi Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -1362,8 +1362,7 @@ ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m, * allocate one and initialize to default values. */ imo = malloc(sizeof(*imo), M_IPMOPTS, M_WAITOK|M_ZERO); - immp = (struct in_multi **)malloc( - (sizeof(*immp) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, + immp = mallocarray(IP_MIN_MEMBERSHIPS, sizeof(*immp), M_IPMOPTS, M_WAITOK|M_ZERO); *imop = imo; imo->imo_ifidx = 0; @@ -1517,9 +1516,8 @@ ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m, omships = imo->imo_membership; newmax = ((imo->imo_max_memberships + 1) * 2) - 1; if (newmax <= IP_MAX_MEMBERSHIPS) { - nmships = (struct in_multi **)mallocarray( - newmax, sizeof(*nmships), M_IPMOPTS, - M_NOWAIT|M_ZERO); + nmships = mallocarray(newmax, sizeof(*nmships), + M_IPMOPTS, M_NOWAIT|M_ZERO); if (nmships != NULL) { memcpy(nmships, omships, sizeof(*omships) * @@ -1623,7 +1621,8 @@ ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m, imo->imo_ttl == IP_DEFAULT_MULTICAST_TTL && imo->imo_loop == IP_DEFAULT_MULTICAST_LOOP && imo->imo_num_memberships == 0) { - free(imo->imo_membership , M_IPMOPTS, 0); + free(imo->imo_membership , M_IPMOPTS, + imo->imo_max_memberships * sizeof(struct in_multi *)); free(*imop, M_IPMOPTS, sizeof(**imop)); *imop = NULL; } @@ -1688,7 +1687,8 @@ ip_freemoptions(struct ip_moptions *imo) if (imo != NULL) { for (i = 0; i < imo->imo_num_memberships; ++i) in_delmulti(imo->imo_membership[i]); - free(imo->imo_membership, M_IPMOPTS, 0); + free(imo->imo_membership, M_IPMOPTS, + imo->imo_max_memberships * sizeof(struct in_multi *)); free(imo, M_IPMOPTS, sizeof(*imo)); } } diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index bb470c8ff32..66b68130ac7 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_output.c,v 1.243 2019/04/28 22:15:58 mpi Exp $ */ +/* $OpenBSD: ip6_output.c,v 1.244 2019/06/10 16:32:51 mpi Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* @@ -1882,9 +1882,7 @@ ip6_setmoptions(int optname, struct ip6_moptions **im6op, struct mbuf *m, * No multicast option buffer attached to the pcb; * allocate one and initialize to default values. */ - im6o = (struct ip6_moptions *) - malloc(sizeof(*im6o), M_IPMOPTS, M_WAITOK); - + im6o = malloc(sizeof(*im6o), M_IPMOPTS, M_WAITOK); if (im6o == NULL) return (ENOBUFS); *im6op = im6o; @@ -2138,7 +2136,7 @@ ip6_setmoptions(int optname, struct ip6_moptions **im6op, struct mbuf *m, im6o->im6o_hlim == ip6_defmcasthlim && im6o->im6o_loop == IPV6_DEFAULT_MULTICAST_LOOP && LIST_EMPTY(&im6o->im6o_memberships)) { - free(*im6op, M_IPMOPTS, 0); + free(*im6op, M_IPMOPTS, sizeof(**im6op)); *im6op = NULL; } @@ -2202,7 +2200,7 @@ ip6_freemoptions(struct ip6_moptions *im6o) LIST_REMOVE(imm, i6mm_chain); in6_leavegroup(imm); } - free(im6o, M_IPMOPTS, 0); + free(im6o, M_IPMOPTS, sizeof(*im6o)); } /* |