diff options
author | Eric Hawicz <erh+git@nimenees.com> | 2020-05-15 21:02:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-15 21:02:37 -0400 |
commit | 4467e94110678c19edb2e36ec9c7e31ef7561a43 (patch) | |
tree | 8b6f46e6251979cc32a3e846bed90c9c05057920 /linkhash.c | |
parent | 228881c8fc287182f284a58d8279a32fbeae0b7f (diff) | |
parent | 5d6fa331418d49f1bd488553fd1cfa9ab023fabb (diff) | |
download | json-c-0.14.tar.gz |
Merge pull request #608 from besser82/topic/besser82/json-c-0.14/CVE-2020-12762json-c-0.14
json-c-0.14: Fix CVE-2020-12762 - json-c through 0.14 has an integer overflow and out-of-bounds write ...
Diffstat (limited to 'linkhash.c')
-rw-r--r-- | linkhash.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; @@ -578,8 +581,12 @@ int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, con unsigned long n; if (t->count >= t->size * LH_LOAD_FACTOR) - if (lh_table_resize(t, t->size * 2) != 0) + { + /* Avoid signed integer overflow with large tables. */ + int new_size = (t->size > INT_MAX / 2) ? INT_MAX : (t->size * 2); + if (t->size == INT_MAX || lh_table_resize(t, new_size) != 0) return -1; + } n = h % t->size; |