File 110-seeding.diff of Package tinyproxy

References: https://banu.com/bugzilla/show_bug.cgi?id=110
References: http://bugzilla.novell.com/776506

@@ -, +, @@ 
---
 configure.ac  |    2 ++
 src/child.c   |    1 +
 src/hashmap.c |   14 ++++++++------
 3 files changed, 11 insertions(+), 6 deletions(-)
Index: tinyproxy-1.8.3/configure.ac
===================================================================
--- tinyproxy-1.8.3.orig/configure.ac
+++ tinyproxy-1.8.3/configure.ac
@@ -205,6 +205,8 @@ AC_CHECK_FUNCS([gethostname inet_ntoa me
 AC_CHECK_FUNCS([isascii memcpy setrlimit ftruncate regcomp regexec])
 AC_CHECK_FUNCS([strlcpy strlcat])
 
+AC_CHECK_FUNCS([time rand srand])
+
 
 dnl Enable extra warnings
 DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -pedantic -Wc++-compat -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
Index: tinyproxy-1.8.3/src/child.c
===================================================================
--- tinyproxy-1.8.3.orig/src/child.c
+++ tinyproxy-1.8.3/src/child.c
@@ -196,6 +196,7 @@ static void child_main (struct child_s *
         }
 
         ptr->connects = 0;
+        srand(time(NULL));
 
         while (!config.quit) {
                 ptr->status = T_WAITING;
Index: tinyproxy-1.8.3/src/hashmap.c
===================================================================
--- tinyproxy-1.8.3.orig/src/hashmap.c
+++ tinyproxy-1.8.3/src/hashmap.c
@@ -50,6 +50,7 @@ struct hashbucket_s {
 };
 
 struct hashmap_s {
+        uint32_t seed;
         unsigned int size;
         hashmap_iter end_iterator;
 
@@ -65,7 +66,7 @@ struct hashmap_s {
  *
  * If any of the arguments are invalid a negative number is returned.
  */
-static int hashfunc (const char *key, unsigned int size)
+static int hashfunc (const char *key, unsigned int size, uint32_t seed)
 {
         uint32_t hash;
 
@@ -74,7 +75,7 @@ static int hashfunc (const char *key, un
         if (size == 0)
                 return -ERANGE;
 
-        for (hash = tolower (*key++); *key != '\0'; key++) {
+        for (hash = seed; *key != '\0'; key++) {
                 uint32_t bit = (hash & 1) ? (1 << (sizeof (uint32_t) - 1)) : 0;
 
                 hash >>= 1;
@@ -104,6 +105,7 @@ hashmap_t hashmap_create (unsigned int n
         if (!ptr)
                 return NULL;
 
+        ptr->seed = (uint32_t)rand();
         ptr->size = nbuckets;
         ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets,
                                                            sizeof (struct
@@ -201,7 +203,7 @@ hashmap_insert (hashmap_t map, const cha
         if (!data || len < 1)
                 return -ERANGE;
 
-        hash = hashfunc (key, map->size);
+        hash = hashfunc (key, map->size, map->seed);
         if (hash < 0)
                 return hash;
 
@@ -382,7 +384,7 @@ ssize_t hashmap_search (hashmap_t map, c
         if (map == NULL || key == NULL)
                 return -EINVAL;
 
-        hash = hashfunc (key, map->size);
+        hash = hashfunc (key, map->size, map->seed);
         if (hash < 0)
                 return hash;
 
@@ -416,7 +418,7 @@ ssize_t hashmap_entry_by_key (hashmap_t
         if (!map || !key || !data)
                 return -EINVAL;
 
-        hash = hashfunc (key, map->size);
+        hash = hashfunc (key, map->size, map->seed);
         if (hash < 0)
                 return hash;
 
@@ -451,7 +453,7 @@ ssize_t hashmap_remove (hashmap_t map, c
         if (map == NULL || key == NULL)
                 return -EINVAL;
 
-        hash = hashfunc (key, map->size);
+        hash = hashfunc (key, map->size, map->seed);
         if (hash < 0)
                 return hash;
 
openSUSE Build Service is sponsored by