diff options
Diffstat (limited to 'meta-openbmc-mods/meta-common/recipes-devtools/json-c/json-c/0002-Prevent-division-by-zero-in-linkhash.patch')
-rw-r--r-- | meta-openbmc-mods/meta-common/recipes-devtools/json-c/json-c/0002-Prevent-division-by-zero-in-linkhash.patch | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/meta-openbmc-mods/meta-common/recipes-devtools/json-c/json-c/0002-Prevent-division-by-zero-in-linkhash.patch b/meta-openbmc-mods/meta-common/recipes-devtools/json-c/json-c/0002-Prevent-division-by-zero-in-linkhash.patch new file mode 100644 index 000000000..447dfe776 --- /dev/null +++ b/meta-openbmc-mods/meta-common/recipes-devtools/json-c/json-c/0002-Prevent-division-by-zero-in-linkhash.patch @@ -0,0 +1,34 @@ +From 77d935b7ae7871a1940cd827e850e6063044ec45 Mon Sep 17 00:00:00 2001 +From: Tobias Stoeckmann <tobias@stoeckmann.org> +Date: Mon, 4 May 2020 19:46:45 +0200 +Subject: [PATCH] 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. +--- + linkhash.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/linkhash.c b/linkhash.c +index 7ea58c0abf..f05cc38030 100644 +--- a/linkhash.c ++++ b/linkhash.c +@@ -12,6 +12,7 @@ + + #include "config.h" + ++#include <assert.h> + #include <stdio.h> + #include <string.h> + #include <stdlib.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; |