diff options
-rw-r--r-- | sys/net/bpf.c | 4 | ||||
-rw-r--r-- | sys/net/bsd-comp.c | 4 | ||||
-rw-r--r-- | sys/net/if_pflog.c | 4 | ||||
-rw-r--r-- | sys/net/pf_if.c | 6 | ||||
-rw-r--r-- | sys/net/ppp-deflate.c | 4 | ||||
-rw-r--r-- | sys/net/radix.c | 4 | ||||
-rw-r--r-- | sys/net/route.c | 18 |
7 files changed, 24 insertions, 20 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c index c951cd2d5ef..8850358811d 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.111 2014/11/23 07:39:02 deraadt Exp $ */ +/* $OpenBSD: bpf.c,v 1.112 2014/12/02 18:11:56 tedu Exp $ */ /* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */ /* @@ -916,8 +916,8 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, int wf) if (flen > BPF_MAXINSNS) return (EINVAL); + fcode = mallocarray(flen, sizeof(*fp->bf_insns), M_DEVBUF, M_WAITOK); size = flen * sizeof(*fp->bf_insns); - fcode = (struct bpf_insn *)malloc(size, M_DEVBUF, M_WAITOK); if (copyin((caddr_t)fp->bf_insns, (caddr_t)fcode, size) == 0 && bpf_validate(fcode, (int)flen)) { s = splnet(); diff --git a/sys/net/bsd-comp.c b/sys/net/bsd-comp.c index 21055eb59cd..c03f62e1d9b 100644 --- a/sys/net/bsd-comp.c +++ b/sys/net/bsd-comp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bsd-comp.c,v 1.8 2014/07/12 18:44:22 tedu Exp $ */ +/* $OpenBSD: bsd-comp.c,v 1.9 2014/12/02 18:11:56 tedu Exp $ */ /* $NetBSD: bsd-comp.c,v 1.6 1996/10/13 02:10:58 christos Exp $ */ /* Because this code is derived from the 4.3BSD compress source: @@ -353,7 +353,7 @@ bsd_alloc(options, opt_len, decomp) if (!decomp) { db->lens = NULL; } else { - db->lens = malloc((maxmaxcode+1) * sizeof(db->lens[0]), M_DEVBUF, + db->lens = mallocarray(maxmaxcode + 1, sizeof(db->lens[0]), M_DEVBUF, M_NOWAIT); if (!db->lens) { free(db, M_DEVBUF, 0); diff --git a/sys/net/if_pflog.c b/sys/net/if_pflog.c index 193541f9983..e4d9b5368e5 100644 --- a/sys/net/if_pflog.c +++ b/sys/net/if_pflog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pflog.c,v 1.64 2014/09/08 18:10:01 bluhm Exp $ */ +/* $OpenBSD: if_pflog.c,v 1.65 2014/12/02 18:11:56 tedu Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -117,7 +117,7 @@ pflogifs_resize(size_t n) if (n == 0) p = NULL; else - if ((p = malloc(n * sizeof(*p), M_DEVBUF, + if ((p = mallocarray(n, sizeof(*p), M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL) return (ENOMEM); for (i = 0; i < n; i++) diff --git a/sys/net/pf_if.c b/sys/net/pf_if.c index f6edb5348e2..2a75d8dfc95 100644 --- a/sys/net/pf_if.c +++ b/sys/net/pf_if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_if.c,v 1.74 2014/07/22 11:06:09 mpi Exp $ */ +/* $OpenBSD: pf_if.c,v 1.75 2014/12/02 18:11:56 tedu Exp $ */ /* * Copyright 2005 Henning Brauer <henning@openbsd.org> @@ -91,7 +91,7 @@ pfi_initialize(void) pool_init(&pfi_addr_pl, sizeof(struct pfi_dynaddr), 0, 0, 0, "pfiaddrpl", &pool_allocator_nointr); pfi_buffer_max = 64; - pfi_buffer = malloc(pfi_buffer_max * sizeof(*pfi_buffer), + pfi_buffer = mallocarray(pfi_buffer_max, sizeof(*pfi_buffer), PFI_MTYPE, M_WAITOK); if ((pfi_all = pfi_kif_get(IFG_ALL)) == NULL) @@ -552,7 +552,7 @@ pfi_address_add(struct sockaddr *sa, int af, int net) pfi_buffer_cnt, PFI_BUFFER_MAX); return; } - p = malloc(new_max * sizeof(*pfi_buffer), PFI_MTYPE, + p = mallocarray(new_max, sizeof(*pfi_buffer), PFI_MTYPE, M_DONTWAIT); if (p == NULL) { DPFPRINTF(LOG_ERR, diff --git a/sys/net/ppp-deflate.c b/sys/net/ppp-deflate.c index b7bc690c483..7d5b0d9dfd6 100644 --- a/sys/net/ppp-deflate.c +++ b/sys/net/ppp-deflate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ppp-deflate.c,v 1.10 2014/07/12 18:44:22 tedu Exp $ */ +/* $OpenBSD: ppp-deflate.c,v 1.11 2014/12/02 18:11:56 tedu Exp $ */ /* $NetBSD: ppp-deflate.c,v 1.1 1996/03/15 02:28:09 paulus Exp $ */ /* @@ -131,7 +131,7 @@ zcalloc(notused, items, size) { void *ptr; - ptr = malloc(items * size, M_DEVBUF, M_NOWAIT); + ptr = mallocarray(items, size, M_DEVBUF, M_NOWAIT); return ptr; } diff --git a/sys/net/radix.c b/sys/net/radix.c index c9108ab0948..e88946ca90b 100644 --- a/sys/net/radix.c +++ b/sys/net/radix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radix.c,v 1.42 2014/07/12 18:44:22 tedu Exp $ */ +/* $OpenBSD: radix.c,v 1.43 2014/12/02 18:11:56 tedu Exp $ */ /* $NetBSD: radix.c,v 1.20 2003/08/07 16:32:56 agc Exp $ */ /* @@ -1185,7 +1185,7 @@ rn_init(void) "rn_init: radix functions require max_keylen be set\n"); return; } - rn_zeros = malloc(3 * max_keylen, M_RTABLE, M_NOWAIT | M_ZERO); + rn_zeros = mallocarray(3, max_keylen, M_RTABLE, M_NOWAIT | M_ZERO); if (rn_zeros == NULL) panic("rn_init"); rn_ones = cp = rn_zeros + max_keylen; diff --git a/sys/net/route.c b/sys/net/route.c index 73f41610b02..d4b2bb58dd0 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.191 2014/11/24 12:43:54 mpi Exp $ */ +/* $OpenBSD: route.c,v 1.192 2014/12/02 18:11:56 tedu Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -190,7 +190,7 @@ rtable_init(struct radix_node_head ***table, u_int id) struct domain *dom; u_int8_t i; - if ((p = malloc(sizeof(void *) * (rtafidx_max + 1), M_RTABLE, + if ((p = mallocarray(rtafidx_max + 1, sizeof(void *), M_RTABLE, M_NOWAIT|M_ZERO)) == NULL) return (ENOMEM); @@ -242,15 +242,19 @@ rtable_add(u_int id) return (EINVAL); if (id == 0 || id > rtbl_id_max) { - size_t newlen = sizeof(void *) * (id+1); - size_t newlen2 = sizeof(u_int) * (id+1); + size_t newlen; + size_t newlen2; - if ((p = malloc(newlen, M_RTABLE, M_NOWAIT|M_ZERO)) == NULL) + if ((p = mallocarray(id + 1, sizeof(void *), M_RTABLE, + M_NOWAIT|M_ZERO)) == NULL) return (ENOMEM); - if ((q = malloc(newlen2, M_RTABLE, M_NOWAIT|M_ZERO)) == NULL) { - free(p, M_RTABLE, 0); + newlen = sizeof(void *) * (id+1); + if ((q = mallocarray(id + 1, sizeof(u_int), M_RTABLE, + M_NOWAIT|M_ZERO)) == NULL) { + free(p, M_RTABLE, newlen); return (ENOMEM); } + newlen2 = sizeof(u_int) * (id+1); if (rt_tables) { bcopy(rt_tables, p, sizeof(void *) * (rtbl_id_max+1)); bcopy(rt_tab2dom, q, sizeof(u_int) * (rtbl_id_max+1)); |