mirror of
https://github.com/apache/httpd.git
synced 2026-01-06 09:01:14 +03:00
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
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user