]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Prevent division by zero in linkhash.
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 4 May 2020 17:46:45 +0000 (19:46 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 4 May 2020 17:46:45 +0000 (19:46 +0200)
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.

linkhash.c

index 7ea58c0abf6c4732f031bf3ff4cf8a1bc3c451db..f05cc38030bf4679f486965a105793100dccd263 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "config.h"
 
+#include <assert.h>
 #include <limits.h>
 #include <stdarg.h>
 #include <stddef.h>
@@ -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;