diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-14 01:18:57 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-14 01:18:57 +0000 |
| commit | c1ff35b781261e8ec97fa3b356d69abe18a2e58d (patch) | |
| tree | b3d31e0a3bff5a269878b792e1c32037e5783c14 /util/nvmutil/nvmutil.c | |
| parent | ad44c1f9b4b6a1da371ec2687fad88372db54e0e (diff) | |
util/nvmutil: handle zero return in rw_file_exact
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/nvmutil.c')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 16 |
1 files changed, 15 insertions, 1 deletions
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, |
