summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-09 17:41:29 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-09 17:41:29 +0000
commit85cc3071bbfebba9daf4a0ba6850e134a03821f1 (patch)
tree4a519fa2fec965a413f640ee60297c8ded095323
parentb2a3edd170a6fbb17584906dde84d2daf94fb27c (diff)
util/nvmutil: even safer rhex()
also handles possible overflows in read_gbe_file_exact it removes dead code on both paths: arc4random and urandom Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/nvmutil/nvmutil.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index a023a48a..8f422eb7 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -932,18 +932,16 @@ rhex(void)
static uint8_t rnum[12];
int max_retries;
- for (max_retries = 0; max_retries < 50 && !n; max_retries++) {
- n = sizeof(rnum);
#ifdef NVMUTIL_ARC4RANDOM_BUF
- arc4random_buf(rnum, n);
+if (!n) {
+ n = sizeof(rnum);
+ arc4random_buf(rnum, n);
+}
#else
+ for (max_retries = 0; max_retries < 50 && !n; max_retries++)
n = (size_t)read_gbe_file_exact(urandom_fd,
- rnum, n, 0, rname, NULL);
-#endif
- }
-
-#ifndef NVMUTIL_ARC4RANDOM_BUF
- if (!n)
+ rnum, sizeof(rnum), 0, rname, NULL);
+ if (!n || n > sizeof(rnum))
err(ECANCELED, "Randomisation failure");
#endif