mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-16 03:25:25 +02:00
util/nvmutil: only open /dev/urandom on setmac
otherwise, it's a pointless computation i also added a guard to mitigate this, in the read file function. this should have been there anyway. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -252,7 +252,8 @@ main(int argc, char *argv[])
|
|||||||
if (cmd == CMD_SETMAC)
|
if (cmd == CMD_SETMAC)
|
||||||
printf("Randomisation method: arc4random_buf\n");
|
printf("Randomisation method: arc4random_buf\n");
|
||||||
#else
|
#else
|
||||||
open_dev_urandom();
|
if (cmd == CMD_SETMAC)
|
||||||
|
open_dev_urandom();
|
||||||
#endif
|
#endif
|
||||||
open_gbe_file();
|
open_gbe_file();
|
||||||
|
|
||||||
@@ -407,8 +408,7 @@ open_dev_urandom(void)
|
|||||||
{
|
{
|
||||||
struct stat st_urandom_fd;
|
struct stat st_urandom_fd;
|
||||||
|
|
||||||
if (cmd == CMD_SETMAC)
|
printf("Randomisation method: %s\n", newrandom);
|
||||||
printf("Randomisation method: %s\n", newrandom);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try /dev/urandom first
|
* Try /dev/urandom first
|
||||||
@@ -417,9 +417,8 @@ open_dev_urandom(void)
|
|||||||
if ((urandom_fd = open(rname, O_RDONLY)) != -1)
|
if ((urandom_fd = open(rname, O_RDONLY)) != -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cmd == CMD_SETMAC)
|
fprintf(stderr, "Can't open %s (will use %s instead)\n",
|
||||||
fprintf(stderr, "Can't open %s (will use %s instead)\n",
|
newrandom, oldrandom);
|
||||||
newrandom, oldrandom);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fall back to /dev/random on old platforms
|
* Fall back to /dev/random on old platforms
|
||||||
@@ -631,6 +630,9 @@ read_file_exact(int fd, void *buf, size_t len,
|
|||||||
int retry;
|
int retry;
|
||||||
ssize_t rval;
|
ssize_t rval;
|
||||||
|
|
||||||
|
if (fd == -1)
|
||||||
|
err(ECANCELED, "Trying to open bad fd: %s", path);
|
||||||
|
|
||||||
for (retry = 0; retry < MAX_RETRY_READ; retry++) {
|
for (retry = 0; retry < MAX_RETRY_READ; retry++) {
|
||||||
if (op)
|
if (op)
|
||||||
rval = pread(fd, buf, len, off);
|
rval = pread(fd, buf, len, off);
|
||||||
|
|||||||
Reference in New Issue
Block a user