diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-09 17:41:29 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-09 17:41:29 +0000 |
| commit | 85cc3071bbfebba9daf4a0ba6850e134a03821f1 (patch) | |
| tree | 4a519fa2fec965a413f640ee60297c8ded095323 | |
| parent | b2a3edd170a6fbb17584906dde84d2daf94fb27c (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.c | 16 |
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 |
