mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-13 14:59:34 +02:00
util/nvmutil: much safer rhex()
n could be zero under weird regression cases Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user