On Sun, Jul 13, 2014 at 11:14, Ted Unangst wrote: > sprinkle malloc array in the kern directory.
And some others from exec that follow a slightly different pattern. Index: exec_elf.c =================================================================== RCS file: /cvs/src/sys/kern/exec_elf.c,v retrieving revision 1.99 diff -u -p -r1.99 exec_elf.c --- exec_elf.c 12 Jul 2014 18:43:32 -0000 1.99 +++ exec_elf.c 13 Jul 2014 23:46:23 -0000 @@ -355,8 +355,8 @@ ELFNAME(load_file)(struct proc *p, char 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, * Allocate space to hold all the program headers, and read them * from the file */ + ph = malloc(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, stru size_t phsize; int error; + hph = malloc(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, voi 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. */ Index: exec_script.c =================================================================== RCS file: /cvs/src/sys/kern/exec_script.c,v retrieving revision 1.30 diff -u -p -r1.30 exec_script.c --- exec_script.c 12 Jul 2014 18:43:32 -0000 1.30 +++ exec_script.c 13 Jul 2014 23:46:23 -0000 @@ -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);