From 4ce184aeb09e65bfefe680c81e1459a59ad64b7c Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Thu, 15 Sep 2011 19:55:56 +0000 Subject: [PATCH] replace non-threadsafe use of srand() and rand() with ap_random_pick() git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1171251 13f79535-47bb-0310-9956-ffa450edef68 --- modules/mappers/mod_rewrite.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 0f6b61f250..8280c0eee9 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -398,9 +398,6 @@ static cache *cachep; /* whether proxy module is available or not */ static int proxy_available; -/* whether random seed can be reaped */ -static int rewrite_rand_init_done = 0; - /* Locks/Mutexes */ static apr_global_mutex_t *rewrite_mapr_lock_acquire = NULL; const char *rewritemap_mutex_type = "rewrite-map"; @@ -1087,18 +1084,7 @@ static char *select_random_value_part(request_rec *r, char *value) } if (n > 1) { - /* initialize random generator - * - * XXX: Probably this should be wrapped into a thread mutex, - * shouldn't it? Is it worth the effort? - */ - if (!rewrite_rand_init_done) { - srand((unsigned)(getpid())); - rewrite_rand_init_done = 1; - } - - /* select a random subvalue */ - n = (int)(((double)(rand() % RAND_MAX) / RAND_MAX) * n + 1); + n = ap_random_pick(1, n); /* extract it from the whole string */ while (--n && (value = ap_strchr(value, '|')) != NULL) { -- 2.40.0