From f03ca35497b3eece2e1c2c2310fe6dd6cc8eb130 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 15 Mar 2026 02:14:23 +0000 Subject: util/nvmutil: fix verified first, in prw loop yes, because otherwise if the offset is still wrong, we allow junk to be written. bad! Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'util/nvmutil') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 4cc35505..fe8364f7 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -2086,19 +2086,6 @@ real_pread_pwrite: loop_eagain, loop_eintr); do { - if (off != verified) - goto err_prw; - - if (rw_type == IO_PREAD) - r = read(fd, mem, nrw); - else if (rw_type == IO_PWRITE) - r = write(fd, mem, nrw); - - if (rw_over_nrw(r, nrw) == -1) { - errno = EIO; - break; - } - /* * Verify again before I/O * (even with OFF_ERR) @@ -2119,6 +2106,19 @@ real_pread_pwrite: verified = lseek_loop(fd, (off_t)0, SEEK_CUR, loop_eagain, loop_eintr); + if (off != verified) + goto err_prw; + + if (rw_type == IO_PREAD) + r = read(fd, mem, nrw); + else if (rw_type == IO_PWRITE) + r = write(fd, mem, nrw); + + if (rw_over_nrw(r, nrw) == -1) { + errno = EIO; + break; + } + } while (r == -1 && (errno == try_err(loop_eintr, EINTR) || errno == try_err(loop_eagain, EAGAIN))); -- cgit v1.2.1