mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user