001-Prevent-division-by-zero-in-linkhash.patch 884 B

1234567891011121314151617181920212223242526272829303132
  1. From 77d935b7ae7871a1940cd827e850e6063044ec45 Mon Sep 17 00:00:00 2001
  2. From: Tobias Stoeckmann <tobias@stoeckmann.org>
  3. Date: Mon, 4 May 2020 19:46:45 +0200
  4. Subject: [PATCH 2/2] Prevent division by zero in linkhash.
  5. If a linkhash with a size of zero is created, then modulo operations
  6. are prone to division by zero operations.
  7. Purely protective measure against bad usage.
  8. ---
  9. linkhash.c | 3 +++
  10. 1 file changed, 3 insertions(+)
  11. --- a/linkhash.c
  12. +++ b/linkhash.c
  13. @@ -10,6 +10,7 @@
  14. *
  15. */
  16. +#include <assert.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <stdlib.h>
  20. @@ -431,6 +432,8 @@ struct lh_table* lh_table_new(int size,
  21. int i;
  22. struct lh_table *t;
  23. + /* Allocate space for elements to avoid divisions by zero. */
  24. + assert(size > 0);
  25. t = (struct lh_table*)calloc(1, sizeof(struct lh_table));
  26. if(!t) lh_abort("lh_table_new: calloc failed\n");
  27. t->count = 0;