mirror of
https://github.com/systemd/systemd.git
synced 2025-02-10 17:57:40 +03:00
Merge pull request #10654 from poettering/srand-rdrand
random-util.c mini-fixes
This commit is contained in:
commit
49a060aca8
@ -142,8 +142,9 @@ void initialize_srand(void) {
|
|||||||
static bool srand_called = false;
|
static bool srand_called = false;
|
||||||
unsigned x;
|
unsigned x;
|
||||||
#if HAVE_SYS_AUXV_H
|
#if HAVE_SYS_AUXV_H
|
||||||
void *auxv;
|
const void *auxv;
|
||||||
#endif
|
#endif
|
||||||
|
uint64_t k;
|
||||||
|
|
||||||
if (srand_called)
|
if (srand_called)
|
||||||
return;
|
return;
|
||||||
@ -153,7 +154,7 @@ void initialize_srand(void) {
|
|||||||
* try to make use of that to seed the pseudo-random generator. It's
|
* try to make use of that to seed the pseudo-random generator. It's
|
||||||
* better than nothing... */
|
* better than nothing... */
|
||||||
|
|
||||||
auxv = (void*) getauxval(AT_RANDOM);
|
auxv = (const void*) getauxval(AT_RANDOM);
|
||||||
if (auxv) {
|
if (auxv) {
|
||||||
assert_cc(sizeof(x) <= 16);
|
assert_cc(sizeof(x) <= 16);
|
||||||
memcpy(&x, auxv, sizeof(x));
|
memcpy(&x, auxv, sizeof(x));
|
||||||
@ -164,6 +165,9 @@ void initialize_srand(void) {
|
|||||||
x ^= (unsigned) now(CLOCK_REALTIME);
|
x ^= (unsigned) now(CLOCK_REALTIME);
|
||||||
x ^= (unsigned) gettid();
|
x ^= (unsigned) gettid();
|
||||||
|
|
||||||
|
if (rdrand64(&k) >= 0)
|
||||||
|
x ^= (unsigned) k;
|
||||||
|
|
||||||
srand(x);
|
srand(x);
|
||||||
srand_called = true;
|
srand_called = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user