From c1ff35b781261e8ec97fa3b356d69abe18a2e58d Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 14 Mar 2026 01:18:57 +0000 Subject: util/nvmutil: handle zero return in rw_file_exact Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'util/nvmutil/nvmutil.c') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 6264537f..01a5e36c 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1611,8 +1611,17 @@ rw_file_exact(int fd, u8 *mem, size_t nrw, for (rc = 0, rv = 0; rc < nrw; ) { if ((rv = rw_file_once(fd, mem, nrw, off, rw_type, rc, - loop_eagain, loop_eintr)) <= 0) + loop_eagain, loop_eintr)) < 0) return -1; + + /* rw_file_once never returns + zero, but it's still logically + incorrect not to handle it here */ + + if (rv == 0) { + errno = EIO; + return -1; + } rc += (size_t)rv; } @@ -1627,6 +1636,11 @@ rw_file_exact(int fd, u8 *mem, size_t nrw, * * May not return all requested bytes (nrw). * Use rw_file_exact for guaranteed length. + * + * This function will never return zero. + * It will only return below (error), + * or above (success). On error, -1 is + * returned and errno is set accordingly. */ static ssize_t rw_file_once(int fd, u8 *mem, size_t nrw, -- cgit v1.2.1