diff options
authorStefan Sperling <ssperling@sysmocom.de>2018-11-21 14:26:18 +0100
committerStefan Sperling <ssperling@sysmocom.de>2018-11-22 07:00:54 +0000
commit411ff3b9842bdc49d833da5682fb71c9cbcbcb8f (patch)
parentaee905b79016fec402e1d3b8fc0e6ce2332cb647 (diff)
fix allocation of ippool's hash table
The calloc() call in ippool_new() had two problems. The first problem is benign: The order of arguments were reversed. Pass the number of elements in the array first, then the size of each element, as calloc() expects. This problem was found by me. There are more instances of this problem in this file, which I'll address in follow-up patches. The second problem is that the requested allocation was larger than necessary: The hash table is an array of pointers to ippoolm_t, not an array of struct ippoolm_t. Fix the required size passed to calloc(). This problem was found by Coverity. Change-Id: I93fa5bc539771ca19714f6a665558c9140e2ce07 Related: CID#57920
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/ippool.c b/lib/ippool.c
index 6561f1f..6ce3cda 100644
--- a/lib/ippool.c
+++ b/lib/ippool.c
@@ -276,9 +276,8 @@ int ippool_new(struct ippool_t **this, const struct in46_prefix *dyn, const stru
(*this)->hashmask = (*this)->hashsize - 1;
/* Allocate hash table */
- if (!
- ((*this)->hash =
- calloc(sizeof(struct ippoolm_t), (*this)->hashsize))) {
+ (*this)->hash = calloc((*this)->hashsize, sizeof(struct ippoolm_t *));
+ if (!(*this)->hash) {
"Failed to allocate memory for hash members in ippool");
return -1;