summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hogan <doug@cvs.openbsd.org>2014-09-24 00:13:14 +0000
committerDoug Hogan <doug@cvs.openbsd.org>2014-09-24 00:13:14 +0000
commit56edc1950595069e4405a5439ab2706258675dc4 (patch)
treec435ba71a8a5ce17ca3cbda5d08d24ed16774217
parent7765166403e6680b36e8f340204bb4fcdb196605 (diff)
Replace a few malloc() calls with reallocarray() so it checks for overflow.
ok deraadt@
-rw-r--r--sys/arch/hppa/stand/mkboot/mkboot.c7
-rw-r--r--sys/arch/hppa64/stand/mkboot/mkboot.c7
-rw-r--r--sys/dev/microcode/bwi/extract/extract.c4
3 files changed, 10 insertions, 8 deletions
diff --git a/sys/arch/hppa/stand/mkboot/mkboot.c b/sys/arch/hppa/stand/mkboot/mkboot.c
index de84d6b6f44..0dd57973acb 100644
--- a/sys/arch/hppa/stand/mkboot/mkboot.c
+++ b/sys/arch/hppa/stand/mkboot/mkboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkboot.c,v 1.18 2014/01/22 09:18:04 jsing Exp $ */
+/* $OpenBSD: mkboot.c,v 1.19 2014/09/24 00:13:13 doug Exp $ */
/*
* Copyright (c) 1990, 1993
@@ -204,10 +204,11 @@ putfile(char *from_file, int to)
if (n != sizeof (elf_header))
err(1, "%s: reading ELF header", from_file);
header_count = ntohs(elf_header.e_phnum);
- memory_needed = header_count * sizeof (*elf_segments);
- elf_segments = malloc(memory_needed);
+ elf_segments = reallocarray(NULL, header_count,
+ sizeof(*elf_segments));
if (elf_segments == NULL)
err(1, "malloc");
+ memory_needed = header_count * sizeof(*elf_segments);
(void) lseek(from, ntohl(elf_header.e_phoff), SEEK_SET);
n = read(from, elf_segments, memory_needed);
if (n != memory_needed)
diff --git a/sys/arch/hppa64/stand/mkboot/mkboot.c b/sys/arch/hppa64/stand/mkboot/mkboot.c
index f92a6eabb75..132fd5d6105 100644
--- a/sys/arch/hppa64/stand/mkboot/mkboot.c
+++ b/sys/arch/hppa64/stand/mkboot/mkboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkboot.c,v 1.4 2014/01/22 09:26:55 jsing Exp $ */
+/* $OpenBSD: mkboot.c,v 1.5 2014/09/24 00:13:13 doug Exp $ */
/*
* Copyright (c) 1990, 1993
@@ -204,10 +204,11 @@ putfile(char *from_file, int to)
if (n != sizeof (elf_header))
err(1, "%s: reading ELF header", from_file);
header_count = betoh32(elf_header.e_phnum);
- memory_needed = header_count * sizeof (*elf_segments);
- elf_segments = malloc(memory_needed);
+ elf_segments = reallocarray(NULL, header_count,
+ sizeof(*elf_segments));
if (elf_segments == NULL)
err(1, "malloc");
+ memory_needed = header_count * sizeof(*elf_segments);
(void) lseek(from, betoh32(elf_header.e_phoff), SEEK_SET);
n = read(from, elf_segments, memory_needed);
if (n != memory_needed)
diff --git a/sys/dev/microcode/bwi/extract/extract.c b/sys/dev/microcode/bwi/extract/extract.c
index a0304b7e500..d7cc17d710b 100644
--- a/sys/dev/microcode/bwi/extract/extract.c
+++ b/sys/dev/microcode/bwi/extract/extract.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: extract.c,v 1.3 2014/07/12 19:01:49 tedu Exp $ */
+/* $OpenBSD: extract.c,v 1.4 2014/09/24 00:13:13 doug Exp $ */
/*
* Copyright (c) 2006 Marcus Glocker <mglocker@openbsd.org>
@@ -53,7 +53,7 @@ main(int argc, char *argv[])
nfiles = ntohl(nfiles);
/* allocate space for header struct */
- if ((h = malloc(nfiles * sizeof(*h))) == NULL)
+ if ((h = reallocarray(NULL, nfiles, sizeof(*h))) == NULL)
err(1, "malloc");
for (i = 0; i < nfiles; i++) {
if ((h[i] = malloc(sizeof(struct header))) == NULL)