mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-19 09:32:27 +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];
|
static uint8_t rnum[12];
|
||||||
int max_retries;
|
int max_retries;
|
||||||
|
|
||||||
for (max_retries = 0; max_retries < 50 && !n; max_retries++) {
|
|
||||||
n = sizeof(rnum);
|
|
||||||
#ifdef NVMUTIL_ARC4RANDOM_BUF
|
#ifdef NVMUTIL_ARC4RANDOM_BUF
|
||||||
arc4random_buf(rnum, n);
|
if (!n) {
|
||||||
|
n = sizeof(rnum);
|
||||||
|
arc4random_buf(rnum, n);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
|
for (max_retries = 0; max_retries < 50 && !n; max_retries++)
|
||||||
n = (size_t)read_gbe_file_exact(urandom_fd,
|
n = (size_t)read_gbe_file_exact(urandom_fd,
|
||||||
rnum, n, 0, rname, NULL);
|
rnum, sizeof(rnum), 0, rname, NULL);
|
||||||
#endif
|
if (!n || n > sizeof(rnum))
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef NVMUTIL_ARC4RANDOM_BUF
|
|
||||||
if (!n)
|
|
||||||
err(ECANCELED, "Randomisation failure");
|
err(ECANCELED, "Randomisation failure");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user