Use mallocarray to allocate multicast group memberships.
authordhill <dhill@openbsd.org>
Sun, 9 Apr 2017 17:57:58 +0000 (17:57 +0000)
committerdhill <dhill@openbsd.org>
Sun, 9 Apr 2017 17:57:58 +0000 (17:57 +0000)
ok deraadt@

sys/net/if_pfsync.c
sys/net/if_vxlan.c
sys/netinet/ip_carp.c
sys/netinet/ip_output.c

index 80f3787..f802983 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: if_pfsync.c,v 1.247 2017/04/05 13:35:18 deraadt Exp $ */
+/*     $OpenBSD: if_pfsync.c,v 1.248 2017/04/09 17:57:58 dhill Exp $   */
 
 /*
  * Copyright (c) 2002 Michael Shalayeff
@@ -316,8 +316,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,
+       sc->sc_imo.imo_membership = (struct in_multi **)mallocarray(
+           IP_MIN_MEMBERSHIPS, sizeof(struct in_multi *), M_IPMOPTS,
            M_WAITOK | M_ZERO);
        sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS;
 
index 4d8620a..a159df9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: if_vxlan.c,v 1.57 2017/01/22 10:17:39 dlg Exp $       */
+/*     $OpenBSD: if_vxlan.c,v 1.58 2017/04/09 17:57:58 dhill Exp $     */
 
 /*
  * Copyright (c) 2013 Reyk Floeter <reyk@openbsd.org>
@@ -129,8 +129,8 @@ vxlan_clone_create(struct if_clone *ifc, int unit)
            M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
                return (ENOMEM);
 
-       sc->sc_imo.imo_membership = malloc(
-           (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS,
+       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);
index 9944b4a..59ad35d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ip_carp.c,v 1.305 2017/04/05 13:35:18 deraadt Exp $   */
+/*     $OpenBSD: ip_carp.c,v 1.306 2017/04/09 17:57:58 dhill Exp $     */
 
 /*
  * Copyright (c) 2002 Michael Shalayeff. All rights reserved.
@@ -795,8 +795,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,
+       sc->sc_imo.imo_membership = (struct in_multi **)mallocarray(
+           IP_MIN_MEMBERSHIPS, sizeof(struct in_multi *), M_IPMOPTS,
            M_WAITOK|M_ZERO);
        sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS;
 
index 09ddca3..3802b83 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ip_output.c,v 1.336 2017/02/09 15:19:32 jca Exp $     */
+/*     $OpenBSD: ip_output.c,v 1.337 2017/04/09 17:57:58 dhill Exp $   */
 /*     $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $  */
 
 /*
@@ -1344,8 +1344,8 @@ 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 = (struct in_multi **)mallocarray(
+                   IP_MIN_MEMBERSHIPS, sizeof(*immp), M_IPMOPTS,
                    M_WAITOK|M_ZERO);
                *imop = imo;
                imo->imo_ifidx = 0;
@@ -1499,8 +1499,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 **)malloc(
-                                   sizeof(*nmships) * newmax, M_IPMOPTS,
+                               nmships = (struct in_multi **)mallocarray(
+                                   newmax, sizeof(*nmships), M_IPMOPTS,
                                    M_NOWAIT|M_ZERO);
                                if (nmships != NULL) {
                                        memcpy(nmships, omships,