From 7d6f1a6b30db7956fac1261acb6b742895bf506d Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 4 Mar 2026 01:23:19 +0000 Subject: util/nvmutil: handle errno after file read errno shouldn't be set, after reading a file successfully. if it is, that's a bug. handle it accordingly. Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'util/nvmutil') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index ea799997..bff8bab0 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -299,6 +299,9 @@ read_gbe_part(int p, int invert) break; } + if (errno) + err(errno, "Unhandled error on read of file '%s'", fname); + swap(p ^ invert); /* handle big-endian host CPU */ } @@ -420,16 +423,17 @@ read_urandom(uint8_t *rnum, size_t rsize) rsize, retry, "read")) break; } + + if (errno) + err(errno, "Unhandled error on read of file '/dev/urandom'"); } static int check_read_or_die(const char *rpath, ssize_t rval, size_t rsize, int retry, const char *readtype) { - if (rval == (ssize_t) rsize) { - errno = 0; + if (rval == (ssize_t) rsize) return 1; /* Successful read */ - } if (rval != -1) err(ECANCELED, "Short %s, %zd bytes, on file: %s", -- cgit v1.2.1