summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordoug <doug@openbsd.org>2014-10-18 03:19:04 +0000
committerdoug <doug@openbsd.org>2014-10-18 03:19:04 +0000
commite93887f2c44d18b24135c720fd1b2bf5fe1e29b0 (patch)
tree9df8d9e39c21ce331411238cb4791209b1fd6660
parentSimple malloc() to reallocarray() conversion. (diff)
downloadwireguard-openbsd-e93887f2c44d18b24135c720fd1b2bf5fe1e29b0.tar.xz
wireguard-openbsd-e93887f2c44d18b24135c720fd1b2bf5fe1e29b0.zip
Convert some malloc() and realloc() calls to reallocarray().
ok deraadt@
-rw-r--r--libexec/ld.so/ldconfig/prebind.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/libexec/ld.so/ldconfig/prebind.c b/libexec/ld.so/ldconfig/prebind.c
index 76cae473110..08a2d1ea75e 100644
--- a/libexec/ld.so/ldconfig/prebind.c
+++ b/libexec/ld.so/ldconfig/prebind.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: prebind.c,v 1.26 2014/03/18 22:36:30 miod Exp $ */
+/* $OpenBSD: prebind.c,v 1.27 2014/10/18 03:19:04 doug Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
*
@@ -601,14 +601,16 @@ elf_load_object(void *pexe, const char *name)
hashtab = (void *)hash;
object->nbuckets = hashtab[0];
object->nchains = hashtab[1];
- hashsz = (2 + object->nbuckets + object->nchains) *
- sizeof (Elf_Word);
- hash = malloc(hashsz);
+ hash = reallocarray(NULL, 2 + object->nbuckets
+ + object->nchains, sizeof(Elf_Word));
if (hash == NULL) {
printf("unable to allocate hash for %s\n",
name);
exit(10);
}
+ hashsz = (2 + object->nbuckets + object->nchains) *
+ sizeof(Elf_Word);
+
bcopy(object->dyn.hash, hash, hashsz);
object->dyn.hash = hash;
object->buckets = ((Elf_Word *)hash + 2);
@@ -963,8 +965,8 @@ add_fixup_prog(struct elf_object *prog, struct elf_object *obj, int idx,
if (pl->fixupcntalloc[libidx] < pl->fixupcnt[libidx] + 1) {
pl->fixupcntalloc[libidx] += 16;
- pl->fixup[libidx] = realloc(pl->fixup[libidx],
- sizeof (struct fixup) * pl->fixupcntalloc[libidx]);
+ pl->fixup[libidx] = reallocarray(pl->fixup[libidx],
+ pl->fixupcntalloc[libidx], sizeof(struct fixup));
if (pl->fixup[libidx] == NULL) {
printf("realloc fixup, out of memory\n");
exit(20);
@@ -2125,8 +2127,8 @@ elf_add_object(struct elf_object *object, int objtype)
TAILQ_INSERT_TAIL(&library_list, ol, list);
if (objarray_cnt+1 >= objarray_sz) {
objarray_sz += 512;
- newarray = realloc(objarray, sizeof (objarray[0]) *
- objarray_sz);
+ newarray = reallocarray(objarray, objarray_sz,
+ sizeof(objarray[0]));
if (newarray != NULL)
objarray = newarray;
else {