diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-18 04:21:18 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-18 04:21:18 +0000 |
| commit | 1ecea3247d8a6694929ee9bf46b2f94f9dabbb79 (patch) | |
| tree | f8e83eceb24594a96c95d095351c0156bd28df70 /util | |
| parent | 7d5384ebb03d7a24ec50ab4432d18519ca8814f2 (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.c | 17 |
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; } |
