From 2e797796a545748ea815f39113088c701b45653f Mon Sep 17 00:00:00 2001 From: Joseph HERLANT Date: Fri, 7 Mar 2014 12:12:39 +0100 Subject: [PATCH] Correcting potential segfault due to division by 0 This happend when passing a weird file name to cmph in generate or verbose mode. To get the crash test script and full report, refer to: http://bugs.debian.org/715745 --- src/jenkins_hash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/jenkins_hash.c b/src/jenkins_hash.c index 13c50d6..e86e113 100644 --- a/src/jenkins_hash.c +++ b/src/jenkins_hash.c @@ -89,7 +89,10 @@ jenkins_state_t *jenkins_state_new(cmph_uint32 size) //size of hash table jenkins_state_t *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t)); if (!state) return NULL; DEBUGP("Initializing jenkins hash\n"); - state->seed = ((cmph_uint32)rand() % size); + if(size > 0) + state->seed = ((cmph_uint32)rand() % size); + else + state->seed = 0; return state; } void jenkins_state_destroy(jenkins_state_t *state)