summaryrefslogtreecommitdiff
path: root/sys/arch/hppa
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 /sys/arch/hppa
parent7765166403e6680b36e8f340204bb4fcdb196605 (diff)
Replace a few malloc() calls with reallocarray() so it checks for overflow.
ok deraadt@
Diffstat (limited to 'sys/arch/hppa')
-rw-r--r--sys/arch/hppa/stand/mkboot/mkboot.c7
1 files changed, 4 insertions, 3 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)