From: Lennart Poettering Date: Thu, 28 Jan 2016 16:00:38 +0000 (+0100) Subject: basic: getauxval(AT_RANDOM) is apparently not necessarily aligned X-Git-Tag: v229~66^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ad6b1fa287c1d007fd85aa3e85b7e4a6bc7f515f;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/basic/random-util.c b/src/basic/random-util.c index e1543da5a37..2f468db770d 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -95,17 +95,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();