diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2020-02-25 16:54:25 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2020-02-25 16:54:25 +0000 |
commit | 10401e27f0a138679431d2c5eeb71daf12f4983a (patch) | |
tree | 165c7205da790d189d037dee09fa30137f4880bf | |
parent | c35a5c5ee24192dfd6dc99e4325ea9bec5a289f5 (diff) |
malloc(a * b) -> reallocarray(NULL, a, b)
ok jsing jca florian
-rw-r--r-- | usr.bin/dig/lib/dns/dst_api.c | 4 | ||||
-rw-r--r-- | usr.bin/dig/lib/dns/hmac_link.c | 12 | ||||
-rw-r--r-- | usr.bin/dig/lib/dns/rdataset.c | 4 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/heap.c | 4 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/hmacsha.c | 12 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/include/isc/safe.h | 14 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/safe.c | 8 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/symtab.c | 6 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/unix/socket.c | 4 |
9 files changed, 24 insertions, 44 deletions
diff --git a/usr.bin/dig/lib/dns/dst_api.c b/usr.bin/dig/lib/dns/dst_api.c index c20cf4745b9..b415581b172 100644 --- a/usr.bin/dig/lib/dns/dst_api.c +++ b/usr.bin/dig/lib/dns/dst_api.c @@ -33,7 +33,7 @@ /* * Principal Author: Brian Wellington - * $Id: dst_api.c,v 1.12 2020/02/24 13:49:38 jsg Exp $ + * $Id: dst_api.c,v 1.13 2020/02/25 16:54:24 deraadt Exp $ */ /*! \file */ @@ -273,7 +273,7 @@ dst_key_free(dst_key_t **keyp) { isc_refcount_destroy(&key->refs); key->func->destroy(key); - isc_safe_memwipe(key, sizeof(*key)); + explicit_bzero(key, sizeof(*key)); free(key); *keyp = NULL; } diff --git a/usr.bin/dig/lib/dns/hmac_link.c b/usr.bin/dig/lib/dns/hmac_link.c index 53d259ef883..e704f92108c 100644 --- a/usr.bin/dig/lib/dns/hmac_link.c +++ b/usr.bin/dig/lib/dns/hmac_link.c @@ -33,7 +33,7 @@ /* * Principal Author: Brian Wellington - * $Id: hmac_link.c,v 1.6 2020/02/23 08:52:50 florian Exp $ + * $Id: hmac_link.c,v 1.7 2020/02/25 16:54:24 deraadt Exp $ */ #include <string.h> @@ -117,7 +117,7 @@ static void hmacsha1_destroy(dst_key_t *key) { dst_hmacsha1_key_t *hkey = key->keydata.hmacsha1; - isc_safe_memwipe(hkey, sizeof(*hkey)); + explicit_bzero(hkey, sizeof(*hkey)); free(hkey); key->keydata.hmacsha1 = NULL; } @@ -262,7 +262,7 @@ static void hmacsha224_destroy(dst_key_t *key) { dst_hmacsha224_key_t *hkey = key->keydata.hmacsha224; - isc_safe_memwipe(hkey, sizeof(*hkey)); + explicit_bzero(hkey, sizeof(*hkey)); free(hkey); key->keydata.hmacsha224 = NULL; } @@ -407,7 +407,7 @@ static void hmacsha256_destroy(dst_key_t *key) { dst_hmacsha256_key_t *hkey = key->keydata.hmacsha256; - isc_safe_memwipe(hkey, sizeof(*hkey)); + explicit_bzero(hkey, sizeof(*hkey)); free(hkey); key->keydata.hmacsha256 = NULL; } @@ -552,7 +552,7 @@ static void hmacsha384_destroy(dst_key_t *key) { dst_hmacsha384_key_t *hkey = key->keydata.hmacsha384; - isc_safe_memwipe(hkey, sizeof(*hkey)); + explicit_bzero(hkey, sizeof(*hkey)); free(hkey); key->keydata.hmacsha384 = NULL; } @@ -697,7 +697,7 @@ static void hmacsha512_destroy(dst_key_t *key) { dst_hmacsha512_key_t *hkey = key->keydata.hmacsha512; - isc_safe_memwipe(hkey, sizeof(*hkey)); + explicit_bzero(hkey, sizeof(*hkey)); free(hkey); key->keydata.hmacsha512 = NULL; } diff --git a/usr.bin/dig/lib/dns/rdataset.c b/usr.bin/dig/lib/dns/rdataset.c index 328c1b72bd4..be37939199a 100644 --- a/usr.bin/dig/lib/dns/rdataset.c +++ b/usr.bin/dig/lib/dns/rdataset.c @@ -285,8 +285,8 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name, shuffle = ISC_TRUE; if (shuffle && count > MAX_SHUFFLE) { - in = malloc(count * sizeof(*in)); - out = malloc(count * sizeof(*out)); + in = reallocarray(NULL, count, sizeof(*in)); + out = reallocarray(NULL, count, sizeof(*out)); if (in == NULL || out == NULL) shuffle = ISC_FALSE; } else { diff --git a/usr.bin/dig/lib/isc/heap.c b/usr.bin/dig/lib/isc/heap.c index 4b03e895dc8..c50de97d59a 100644 --- a/usr.bin/dig/lib/isc/heap.c +++ b/usr.bin/dig/lib/isc/heap.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: heap.c,v 1.5 2020/02/25 05:00:43 jsg Exp $ */ +/* $Id: heap.c,v 1.6 2020/02/25 16:54:24 deraadt Exp $ */ /*! \file * Heap implementation of priority queues adapted from the following: @@ -110,7 +110,7 @@ resize(isc_heap_t *heap) { unsigned int new_size; new_size = heap->size + heap->size_increment; - new_array = malloc(new_size * sizeof(void *)); + new_array = reallocarray(NULL, new_size, sizeof(void *)); if (new_array == NULL) return (ISC_FALSE); if (heap->array != NULL) { diff --git a/usr.bin/dig/lib/isc/hmacsha.c b/usr.bin/dig/lib/isc/hmacsha.c index 2da7d283f19..2548675b7e6 100644 --- a/usr.bin/dig/lib/isc/hmacsha.c +++ b/usr.bin/dig/lib/isc/hmacsha.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: hmacsha.c,v 1.4 2020/02/25 05:00:43 jsg Exp $ */ +/* $Id: hmacsha.c,v 1.5 2020/02/25 16:54:24 deraadt Exp $ */ /* * This code implements the HMAC-SHA1, HMAC-SHA224, HMAC-SHA256, HMAC-SHA384 @@ -65,7 +65,7 @@ isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) { HMAC_CTX_free(ctx->ctx); ctx->ctx = NULL; memmove(digest, newdigest, len); - isc_safe_memwipe(newdigest, sizeof(newdigest)); + explicit_bzero(newdigest, sizeof(newdigest)); } void @@ -103,7 +103,7 @@ isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len) { HMAC_CTX_free(ctx->ctx); ctx->ctx = NULL; memmove(digest, newdigest, len); - isc_safe_memwipe(newdigest, sizeof(newdigest)); + explicit_bzero(newdigest, sizeof(newdigest)); } void @@ -141,7 +141,7 @@ isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len) { HMAC_CTX_free(ctx->ctx); ctx->ctx = NULL; memmove(digest, newdigest, len); - isc_safe_memwipe(newdigest, sizeof(newdigest)); + explicit_bzero(newdigest, sizeof(newdigest)); } void @@ -179,7 +179,7 @@ isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len) { HMAC_CTX_free(ctx->ctx); ctx->ctx = NULL; memmove(digest, newdigest, len); - isc_safe_memwipe(newdigest, sizeof(newdigest)); + explicit_bzero(newdigest, sizeof(newdigest)); } void @@ -217,7 +217,7 @@ isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len) { HMAC_CTX_free(ctx->ctx); ctx->ctx = NULL; memmove(digest, newdigest, len); - isc_safe_memwipe(newdigest, sizeof(newdigest)); + explicit_bzero(newdigest, sizeof(newdigest)); } /* diff --git a/usr.bin/dig/lib/isc/include/isc/safe.h b/usr.bin/dig/lib/isc/include/isc/safe.h index a6bd69b5957..516036d22d3 100644 --- a/usr.bin/dig/lib/isc/include/isc/safe.h +++ b/usr.bin/dig/lib/isc/include/isc/safe.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: safe.h,v 1.3 2020/02/13 13:53:01 jsg Exp $ */ +/* $Id: safe.h,v 1.4 2020/02/25 16:54:24 deraadt Exp $ */ #ifndef ISC_SAFE_H #define ISC_SAFE_H 1 @@ -32,16 +32,4 @@ isc_safe_memequal(const void *s1, const void *s2, size_t n); * */ -void -isc_safe_memwipe(void *ptr, size_t len); -/*%< - * Clear the memory of length `len` pointed to by `ptr`. - * - * Some crypto code calls memset() on stack allocated buffers just - * before return so that they are wiped. Such memset() calls can be - * optimized away by the compiler. We provide this external non-inline C - * function to perform the memset operation so that the compiler cannot - * infer about what the function does and optimize the call away. - */ - #endif /* ISC_SAFE_H */ diff --git a/usr.bin/dig/lib/isc/safe.c b/usr.bin/dig/lib/isc/safe.c index f6fac434c85..496d1fa496d 100644 --- a/usr.bin/dig/lib/isc/safe.c +++ b/usr.bin/dig/lib/isc/safe.c @@ -33,11 +33,3 @@ isc_safe_memequal(const void *s1, const void *s2, size_t n) { } return (ISC_TF(acc == 0)); } - -void -isc_safe_memwipe(void *ptr, size_t len) { - if (ptr == NULL || len == 0) - return; - - explicit_bzero(ptr, len); -} diff --git a/usr.bin/dig/lib/isc/symtab.c b/usr.bin/dig/lib/isc/symtab.c index a4066769745..948b52a3738 100644 --- a/usr.bin/dig/lib/isc/symtab.c +++ b/usr.bin/dig/lib/isc/symtab.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: symtab.c,v 1.4 2020/02/25 05:00:43 jsg Exp $ */ +/* $Id: symtab.c,v 1.5 2020/02/25 16:54:24 deraadt Exp $ */ /*! \file */ @@ -61,7 +61,7 @@ isc_symtab_create(unsigned int size, if (symtab == NULL) return (ISC_R_NOMEMORY); - symtab->table = (eltlist_t *)malloc(size * sizeof(eltlist_t)); + symtab->table = (eltlist_t *)reallocarray(NULL, size, sizeof(eltlist_t)); if (symtab->table == NULL) { free(symtab); return (ISC_R_NOMEMORY); @@ -176,7 +176,7 @@ grow_table(isc_symtab_t *symtab) { newmax = newsize * 3 / 4; INSIST(newsize > 0U && newmax > 0U); - newtable = malloc(newsize * sizeof(eltlist_t)); + newtable = reallocarray(NULL, newsize, sizeof(eltlist_t)); if (newtable == NULL) return; diff --git a/usr.bin/dig/lib/isc/unix/socket.c b/usr.bin/dig/lib/isc/unix/socket.c index b447b31f657..0a2ea57e29e 100644 --- a/usr.bin/dig/lib/isc/unix/socket.c +++ b/usr.bin/dig/lib/isc/unix/socket.c @@ -1821,12 +1821,12 @@ isc_socketmgr_create2(isc_socketmgr_t **managerp, /* zero-clear so that necessary cleanup on failure will be easy */ memset(manager, 0, sizeof(*manager)); manager->maxsocks = maxsocks; - manager->fds = malloc(manager->maxsocks * sizeof(isc_socket_t *)); + manager->fds = reallocarray(NULL, manager->maxsocks, sizeof(isc_socket_t *)); if (manager->fds == NULL) { result = ISC_R_NOMEMORY; goto free_manager; } - manager->fdstate = malloc(manager->maxsocks * sizeof(int)); + manager->fdstate = reallocarray(NULL, manager->maxsocks, sizeof(int)); if (manager->fdstate == NULL) { result = ISC_R_NOMEMORY; goto free_manager; |