util/nvmutil: prevent overflow in rw_file_exact

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-14 17:49:18 +00:00
parent c02dfc4c33
commit 01fd54bc11

View File

@@ -1860,6 +1860,10 @@ rw_file_exact(int fd, u8 *mem, size_t nrw,
return -1;
}
/* Prevent theoretical overflow */
if (rv > nrw - rc)
goto err_rw_file_exact;
rc += (size_t)rv;
}