summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-14 22:43:22 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-14 22:47:16 +0000
commitef4e9dc895e3e2454c904548a7d0e78235a1767f (patch)
treefcb19a79613a252e90354db83fbd52d91b7eb48e /util/nvmutil
parent93603e1572ead36b16f9a421444df061ebf83b90 (diff)
util/nvmutil: rw file: guard rc before addition
otherwise, it could still overflow Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index b3cea8da..9218b827 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -1882,6 +1882,10 @@ rw_file_exact(int fd, u8 *mem, size_t nrw,
size_t retries_on_zero = 0;
while (1) {
+
+ /* Prevent theoretical overflow */
+ if ((size_t)rv > (nrw - rc))
+ goto err_rw_file_exact;
rc += rv;
if ((size_t)rc >= nrw)
@@ -1896,10 +1900,6 @@ rw_file_exact(int fd, u8 *mem, size_t nrw,
if (rv < 0)
return -1;
-
- /* Prevent theoretical overflow */
- if ((size_t)rv > (nrw - rc))
- goto err_rw_file_exact;
if (rv == 0) {
if (retries_on_zero++ < max_retries)