From f509c87d045654269cc1692a209d7213d673c1dc Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 15 Mar 2026 01:06:36 +0000 Subject: 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 --- util/nvmutil/nvmutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 2d613f81..d05d25ce 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -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; -- cgit v1.2.1