summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-18 04:21:18 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-26 06:59:42 +0000
commite3a007a8aee9b8ee4d8ba9bb5dd8339040528c8c (patch)
treec42e7df1a30d4f8cea11ef73c9d723dd60ab162d /util
parentcdce83d19e80435b1856824c2fac8747a566c3f4 (diff)
nvmutil: don't read urandom fd if fd not open
yeah. obvious bug Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 8495836f..e6f43da6 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -1051,15 +1051,18 @@ rlong(void)
if (fd < 0)
fd = open("/dev/random", O_RDONLY | O_BINARY | O_NONBLOCK);
- nr = rw_file_exact(fd, (unsigned char *)&rval,
- sizeof(unsigned long), 0, IO_READ, LOOP_EAGAIN,
- LOOP_EINTR, MAX_ZERO_RW_RETRY, OFF_ERR);
+ if (fd > -1) {
- if (x_i_close(fd) < 0)
- err(errno, "Can't close randomness fd");
+ nr = rw_file_exact(fd, (unsigned char *)&rval,
+ sizeof(unsigned long), 0, IO_READ, LOOP_EAGAIN,
+ LOOP_EINTR, MAX_ZERO_RW_RETRY, OFF_ERR);
- if (nr == sizeof(unsigned long))
- return rval;
+ if (x_i_close(fd) < 0)
+ err(errno, "Can't close randomness fd");
+
+ if (nr == sizeof(unsigned long))
+ return rval;
+ }
return mix;
}