summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-08 02:39:53 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-08 02:39:53 +0000
commit1bbc6ac8901b5a9d62c05337883bc2bfce26b2fc (patch)
tree73baa8ff78e62bd650f53e8c747951e873d8a7ae
parent9bd7d04b49464f2c9d368c5d24451a5638b4751d (diff)
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>
-rw-r--r--util/nvmutil/nvmutil.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 65c1b0eb..7fbb3460 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -252,7 +252,8 @@ main(int argc, char *argv[])
if (cmd == CMD_SETMAC)
printf("Randomisation method: arc4random_buf\n");
#else
- open_dev_urandom();
+ if (cmd == CMD_SETMAC)
+ open_dev_urandom();
#endif
open_gbe_file();
@@ -407,8 +408,7 @@ open_dev_urandom(void)
{
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
@@ -417,9 +417,8 @@ open_dev_urandom(void)
if ((urandom_fd = open(rname, O_RDONLY)) != -1)
return;
- if (cmd == CMD_SETMAC)
- fprintf(stderr, "Can't open %s (will use %s instead)\n",
- newrandom, oldrandom);
+ fprintf(stderr, "Can't open %s (will use %s instead)\n",
+ newrandom, oldrandom);
/*
* Fall back to /dev/random on old platforms
@@ -631,6 +630,9 @@ read_file_exact(int fd, void *buf, size_t len,
int retry;
ssize_t rval;
+ if (fd == -1)
+ err(ECANCELED, "Trying to open bad fd: %s", path);
+
for (retry = 0; retry < MAX_RETRY_READ; retry++) {
if (op)
rval = pread(fd, buf, len, off);