diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-09 17:00:58 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-09 17:02:14 +0000 |
| commit | 61015dbc6c1050a21454eb891c38ee5408c4a154 (patch) | |
| tree | f46b091ee923fdc91af139bafebde62b29628efb /util | |
| parent | f34d020a2015ee7895ca8e044c605a528674bac6 (diff) | |
util/nvmutil: much safer rhex()
n could be zero under weird regression cases
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index e16b227c..c069cc6e 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -930,8 +930,9 @@ rhex(void) { static size_t n = 0; static uint8_t rnum[12]; + int max_retries; - if (!n) { + for (max_retries = 0; max_retries < 50 && !n; max_retries++) { n = sizeof(rnum); #ifdef NVMUTIL_ARC4RANDOM_BUF arc4random_buf(rnum, n); @@ -941,6 +942,9 @@ rhex(void) #endif } + if (!n) + err(ECANCELED, "Randomisation failure"); + return (uint16_t)(rnum[--n] & 0xf); } |
