summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-12 14:13:55 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-12 14:13:55 +0000
commit922344e81e91b1c5f686bdd9f669d5f884624a69 (patch)
tree7ccfdd069b2a18998b106d925922048dab3664e1 /util/nvmutil
parent53c5a400078b631bd1e433617691104fc2eab818 (diff)
util/nvmutil: mitigate fast calls to rand
if someone calls rhex fast enough, the timestamp may not change. this mitigates that by adding a counter value to the mix Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 68840789..aa3e9192 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -1032,13 +1032,15 @@ fallback_rand(void)
{
struct timeval tv;
unsigned long mix;
+ static unsigned long counter = 0;
gettimeofday(&tv, NULL);
mix = (unsigned long)tv.tv_sec
^ (unsigned long)tv.tv_usec
^ (unsigned long)getpid()
- ^ (unsigned long)(uintptr_t)&mix;
+ ^ (unsigned long)&mix
+ ^ counter++;
return (uint16_t)(mix & 0xf);
}