Commit 66db9939 authored by Pekka Pessi's avatar Pekka Pessi

su_uniqueid.c: fixed seed array usage

Ignore-this: b6e6a195f3f34abc2119a741f8b6f5e2

Paper bags, anyone?

darcs-hash:20090225172923-db55f-0fa6714e718df426e67da51414434551fa272d7e.gz
parent 75068d69
......@@ -136,11 +136,14 @@ static void init(void)
{
int i;
#define N_SEED 32
#if HAVE_INITSTATE
/* Allow libsofia-sip-ua.so to unload. */
uint32_t *seed = calloc(32, sizeof *seed);
uint32_t *seed = calloc(N_SEED, sizeof *seed);
#else
static uint32_t seed[32] = { 0 };
static uint32_t _seed[N_SEED] = { 0 };
uint32_t *seed = _seed;
#endif
su_time_t now;
......@@ -153,25 +156,25 @@ static void init(void)
#endif /* HAVE_DEV_URANDOM */
if (urandom) {
size_t len = fread(seed, sizeof seed, 1, urandom); (void)len;
size_t len = fread(seed, sizeof *seed, N_SEED, urandom); (void)len;
}
else {
for (i = 0; i < 16; i++) {
for (i = 0; i < N_SEED; i += 2) {
#if HAVE_CLOCK_GETTIME
struct timespec ts;
(void)clock_gettime(CLOCK_REALTIME, &ts);
seed[2*i] ^= ts.tv_sec; seed[2*i+1] ^= ts.tv_nsec;
seed[i] ^= ts.tv_sec; seed[i + 1] ^= ts.tv_nsec;
#endif
su_time(&now);
seed[2*i] ^= now.tv_sec; seed[2*i+1] ^= now.tv_sec;
seed[i] ^= now.tv_sec; seed[i + 1] ^= now.tv_sec;
}
seed[30] ^= getuid();
seed[31] ^= getpid();
seed[0] ^= getuid();
seed[1] ^= getpid();
}
#if HAVE_INITSTATE
initstate(seed[0] ^ seed[1], (char *)&seed, sizeof(seed));
initstate(seed[0] ^ seed[1], (void *)seed, N_SEED * (sizeof *seed));
#else
srand(seed[0] ^ seed[1]);
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment