From adf3aece6faa134379bde6f72ae0521b7012f707 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 1 Jun 2023 12:58:33 +0100 Subject: util/nvmutil: fix faulty fd check i screwed up in an earlier commit this change fixes a bug where on rhex(), each call would re-open /dev/urandom, resetting rfd Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'util/nvmutil/nvmutil.c') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 77b33aa2..38d34436 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -141,9 +141,12 @@ rhex(void) { static int rfd = -1, n = 0; static uint8_t rnum[16]; - xopen(rfd, "/dev/urandom", O_RDONLY); - if (!n) + if (!n) { + if (rfd == -1) { + xopen(rfd, "/dev/urandom", O_RDONLY); + } xpread(rfd, (uint8_t *) &rnum, (n = 15) + 1, 0, "/dev/urandom"); + } return rnum[n--] & 0xf; } -- cgit v1.2.1