From b968dec77d784e20d45a4d389be35301c9059b34 Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 31 Mar 2025 03:21:51 +0000 Subject: [PATCH] misc/random: improve the fallback case c365e2f7 added av_random_bytes() to avoid multiple threads/processes getting the same seed. but the fallback case still suffers from it. also mix in a function pointer, which hopefully is randomized per process due to ASLR (20+ years old technology) along with the stack position which will be different on different threads. --- misc/random.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/misc/random.c b/misc/random.c index 3d6fe98a7b..d3b2a62da4 100644 --- a/misc/random.c +++ b/misc/random.c @@ -52,6 +52,8 @@ mp_rand_state mp_rand_seed(uint64_t seed) return ret; } seed = mp_raw_time_ns(); + seed ^= (uintptr_t)&mp_rand_seed; // ASLR, hopefully + seed += (uintptr_t)&ret; // stack position } ret.v[0] = seed;