From: tedu Date: Sun, 13 Jul 2014 23:59:58 +0000 (+0000) Subject: use mallocarray for multiplied value checking X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=8cc2fc565664ba2dd04a48c2b1093fd84d34db8f;p=openbsd use mallocarray for multiplied value checking --- diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c index 7df3832810e..046b5d8d146 100644 --- a/sys/kern/exec_elf.c +++ b/sys/kern/exec_elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.c,v 1.99 2014/07/12 18:43:32 tedu Exp $ */ +/* $OpenBSD: exec_elf.c,v 1.100 2014/07/13 23:59:58 tedu Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom @@ -355,8 +355,8 @@ ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp, goto bad1; } + ph = mallocarray(eh.e_phnum, sizeof(Elf_Phdr), M_TEMP, M_WAITOK); phsize = eh.e_phnum * sizeof(Elf_Phdr); - ph = malloc(phsize, M_TEMP, M_WAITOK); if ((error = ELFNAME(read_from)(p, nd.ni_vp, eh.e_phoff, (caddr_t)ph, phsize)) != 0) @@ -539,8 +539,8 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) * Allocate space to hold all the program headers, and read them * from the file */ + ph = mallocarray(eh->e_phnum, sizeof(Elf_Phdr), M_TEMP, M_WAITOK); phsize = eh->e_phnum * sizeof(Elf_Phdr); - ph = malloc(phsize, M_TEMP, M_WAITOK); if ((error = ELFNAME(read_from)(p, epp->ep_vp, eh->e_phoff, (caddr_t)ph, phsize)) != 0) @@ -860,8 +860,8 @@ ELFNAME(os_pt_note)(struct proc *p, struct exec_package *epp, Elf_Ehdr *eh, size_t phsize; int error; + hph = mallocarray(eh->e_phnum, sizeof(Elf_Phdr), M_TEMP, M_WAITOK); phsize = eh->e_phnum * sizeof(Elf_Phdr); - hph = malloc(phsize, M_TEMP, M_WAITOK); if ((error = ELFNAME(read_from)(p, epp->ep_vp, eh->e_phoff, (caddr_t)hph, phsize)) != 0) goto out1; @@ -1005,7 +1005,7 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie) notestart = offset + sizeof(phdr) * cs.npsections; secstart = notestart + notesize; - psections = malloc(cs.npsections * sizeof(Elf_Phdr), + psections = mallocarray(cs.npsections, sizeof(Elf_Phdr), M_TEMP, M_WAITOK|M_ZERO); /* Pass 2: now write the P-section headers. */ diff --git a/sys/kern/exec_script.c b/sys/kern/exec_script.c index a8e327e3ba1..ede81cbbd41 100644 --- a/sys/kern/exec_script.c +++ b/sys/kern/exec_script.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_script.c,v 1.30 2014/07/12 18:43:32 tedu Exp $ */ +/* $OpenBSD: exec_script.c,v 1.31 2014/07/13 23:59:58 tedu Exp $ */ /* $NetBSD: exec_script.c,v 1.13 1996/02/04 02:15:06 christos Exp $ */ /* @@ -208,7 +208,7 @@ check_shell: epp->ep_flags |= EXEC_INDIR; /* and set up the fake args list, for later */ - shellargp = malloc(4 * sizeof(char *), M_EXEC, M_WAITOK); + shellargp = mallocarray(4, sizeof(char *), M_EXEC, M_WAITOK); tmpsap = shellargp; *tmpsap = malloc(shellnamelen + 1, M_EXEC, M_WAITOK); strlcpy(*tmpsap++, shellname, shellnamelen + 1);