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 <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-15 02:14:23 +00:00
parent 31835eb8e3
commit 0d6bb8d747
+13 -13
View File
@@ -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)));