From: Tobias Stoeckmann Date: Mon, 4 May 2020 17:46:45 +0000 (+0200) Subject: Prevent division by zero in linkhash. X-Git-Tag: json-c-0.15-20200726~58^2~2^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77d935b7ae7871a1940cd827e850e6063044ec45;p=json-c Prevent division by zero in linkhash. If a linkhash with a size of zero is created, then modulo operations are prone to division by zero operations. Purely protective measure against bad usage. --- diff --git a/linkhash.c b/linkhash.c index 7ea58c0..f05cc38 100644 --- a/linkhash.c +++ b/linkhash.c @@ -12,6 +12,7 @@ #include "config.h" +#include #include #include #include @@ -499,6 +500,8 @@ struct lh_table *lh_table_new(int size, lh_entry_free_fn *free_fn, lh_hash_fn *h int i; struct lh_table *t; + /* Allocate space for elements to avoid divisions by zero. */ + assert(size > 0); t = (struct lh_table *)calloc(1, sizeof(struct lh_table)); if (!t) return NULL;