On Mon, 2012-01-16 at 08:38 +1100, Bojan Smojver wrote:
> That is true. In fact, my first code to the list just used ht. We
> could use ht and time to get "random" values. Same attack vectors as
> noted by you above apply, of course. 

Maybe like this?

-- 
Bojan
Index: tables/apr_hash.c
===================================================================
--- tables/apr_hash.c	(revision 1231774)
+++ tables/apr_hash.c	(working copy)
@@ -19,9 +19,6 @@
 #include "apr_general.h"
 #include "apr_pools.h"
 #include "apr_time.h"
-#if APR_HAVE_STDLIB_H
-#include <stdlib.h>     /* for rand, srand */
-#endif
 
 #include "apr_hash.h"
 
@@ -106,8 +103,8 @@
     ht->free = NULL;
     ht->count = 0;
     ht->max = INITIAL_MAX;
-    srand((unsigned int)((now >> 32) ^ now ^ (apr_uintptr_t)ht));
-    ht->seed = (unsigned int)(rand());
+    ht->seed = (unsigned int)(((now >> 32) ^ (apr_uintptr_t)ht) ^
+                              (now ^ (apr_uintptr_t)&now));
     ht->array = alloc_array(ht, ht->max);
     ht->hash_func = NULL;
 

Reply via email to