summaryrefslogtreecommitdiff
path: root/src/basic/random-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-01-28 17:00:38 +0100
committerSven Eden <yamakuzure@gmx.net>2017-05-17 15:22:15 +0200
commit9e830df83c27d0d757df16904ec23b3844da2733 (patch)
tree0a676ea98f933ec5b186f92194ab57aa00ad1ead /src/basic/random-util.c
parent03ecdfcc404d4066dfae119d3ce27266fc0bfa88 (diff)
basic: getauxval(AT_RANDOM) is apparently not necessarily aligned
Let's make sure we read it in a way compatible with non-aligned memory. Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=812928
Diffstat (limited to 'src/basic/random-util.c')
-rw-r--r--src/basic/random-util.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/basic/random-util.c b/src/basic/random-util.c
index 2f5c16e2a..34cc7cbce 100644
--- a/src/basic/random-util.c
+++ b/src/basic/random-util.c
@@ -94,17 +94,18 @@ void initialize_srand(void) {
if (srand_called)
return;
- x = 0;
-
#ifdef HAVE_SYS_AUXV_H
- /* The kernel provides us with a bit of entropy in auxv, so
- * let's try to make use of that to seed the pseudo-random
- * generator. It's better than nothing... */
+ /* The kernel provides us with 16 bytes of entropy in auxv, so let's try to make use of that to seed the
+ * pseudo-random generator. It's better than nothing... */
auxv = (void*) getauxval(AT_RANDOM);
- if (auxv)
- x ^= *(unsigned*) auxv;
+ if (auxv) {
+ assert_cc(sizeof(x) < 16);
+ memcpy(&x, auxv, sizeof(x));
+ } else
#endif
+ x = 0;
+
x ^= (unsigned) now(CLOCK_REALTIME);
x ^= (unsigned) gettid();