util/nvmutil: prevent underflow in comparison

we already check before that rv is not negative,
and it starts at zero, but it's good to guard
it here just in case (for future re-factoring).

if rv is negative, it could convert (casted to
size_t) to a huge number (we don't want that).

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-15 01:06:36 +00:00
parent d148985e61
commit 8d81e8f68b
+1 -1
View File
@@ -1908,7 +1908,7 @@ rw_file_exact(int fd, u8 *mem, size_t nrw,
while (1) {
/* Prevent theoretical overflow */
if ((size_t)rv > (nrw - rc))
if (rv >= 0 && (size_t)rv > (nrw - rc))
goto err_rw_file_exact;
rc += rv;