b=327161, real and final fix for btek's orange in uuidgenerator glibc brokenness, r+sr=bz

This commit is contained in:
vladimir%pobox.com 2006-08-15 00:52:21 +00:00
Родитель e9242e8802
Коммит 8827e3f637
2 изменённых файлов: 9 добавлений и 10 удалений

Просмотреть файл

@ -90,17 +90,12 @@ nsUUIDGenerator::Init()
bytes += nbytes;
}
// call random once for the side effect of initializing
// glibc's internal state, so that initstate doesn't
// return NULL
random();
/* Initialize a new RNG state, and immediately switch
* back to the previous one -- we want to use mState
* only for our own calls to random().
*/
char *oldstate = initstate(seed, mState, sizeof(mState));
setstate(oldstate);
mSavedState = initstate(seed, mState, sizeof(mState));
setstate(mSavedState);
mRBytes = 4;
#ifdef RAND_MAX
@ -157,8 +152,11 @@ nsUUIDGenerator::GenerateUUIDInPlace(nsID* id)
CFRelease(uuid);
#else /* not windows or OS X; generate randomness using random(). */
/* Switch to our RNG state, and save off the old one */
char *oldstate = setstate(mState);
/* XXX we should be saving the return of setstate here and switching
* back to it; instead, we use the value returned when we called
* initstate, since older glibc's have broken setstate() return values
*/
setstate(mState);
PRSize bytesLeft = sizeof(nsID);
while (bytesLeft > 0) {
@ -187,7 +185,7 @@ nsUUIDGenerator::GenerateUUIDInPlace(nsID* id)
id->m3[0] |= 0x80;
/* Restore the previous RNG state */
setstate(oldstate);
setstate(mSavedState);
#endif
return NS_OK;

Просмотреть файл

@ -60,6 +60,7 @@ protected:
PRLock* mLock;
#if !defined(XP_WIN) && !defined(XP_MACOSX)
char mState[32];
char *mSavedState;
PRUint8 mRBytes;
#endif
};