diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-14 03:29:01 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-14 03:40:46 +0000 |
| commit | eb8a297ba0b189fd93eef19e21e3c275f756c0c9 (patch) | |
| tree | 7662074099569810300856a902edc4abcef6173d /util/nvmutil/nvmutil.c | |
| parent | 76a00c48b49e53be9a43b3c2293f36eb91abde78 (diff) | |
util/nvmutil: detect partial gbe rw
we already covered this in prw() which is
what ultimately gets called, but still.
it's logically correct not to check it here.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/nvmutil.c')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 0f3158e7..0292a4cb 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1489,6 +1489,7 @@ static void rw_gbe_file_part(size_t p, int rw_type, const char *rw_type_str) { + ssize_t r; size_t gbe_rw_size = command[cmd_index].rw_size; u8 invert = command[cmd_index].invert; @@ -1509,11 +1510,17 @@ rw_gbe_file_part(size_t p, int rw_type, mem_offset = gbe_mem_offset(p ^ invert, rw_type_str); file_offset = (off_t)gbe_file_offset(p, rw_type_str); - if (rw_gbe_file_exact(gbe_fd, mem_offset, - gbe_rw_size, file_offset, rw_type) == -1) + r = rw_gbe_file_exact(gbe_fd, mem_offset, + gbe_rw_size, file_offset, rw_type); + + if (r == -1) err(errno, "%s: %s: part %lu", fname, rw_type_str, (ulong)p); + if ((size_t)r != gbe_rw_size) + err(EIO, "%s: partial %s: part %lu", + fname, rw_type_str, (ulong)p); + /* * Next, we read back what was written, * to ensure that it was done correctly. @@ -1531,12 +1538,18 @@ rw_gbe_file_part(size_t p, int rw_type, err(errno, "%s: fsync: part %lu (post-verification)", fname, (ulong)p); - if (rw_gbe_file_exact(gbe_fd, pad, - gbe_rw_size, file_offset, IO_PREAD) == -1) + r = rw_gbe_file_exact(gbe_fd, pad, + gbe_rw_size, file_offset, IO_PREAD); + + if (r == -1) err(errno, "%s: pread: part %lu (post-verification)", fname, (ulong)p); - if (memcmp(mem_offset, pad, gbe_rw_size)) + if ((size_t)r != gbe_rw_size) + err(EIO, "%s: partial pread: part %lu (post-verification)", + fname, (ulong)p); + + if (memcmp(mem_offset, pad, gbe_rw_size) != 0) err(errno, "%s: pwrite: corrupt write on part %lu", fname, (ulong)p); } |
