Commit 623d71ea authored by Stefan Fritsch's avatar Stefan Fritsch
Browse files

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
parent ca420293
Loading
Loading
Loading
Loading
+1 −15
Changes for modules/mappers/mod_rewrite.c: 1 added line, 15 removed lines.
Original line number Diff line number Diff line
@@ -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) {