summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-14 23:29:11 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-26 06:59:41 +0000
commit7263125d60bb9bee885cc0f6fa60e8a148d0a758 (patch)
tree6704cf732e5ff3bd0fd509f57d9ba76b37518f16 /util
parenta89747a5c8657e93e20834c6f2bc61a1b8e0ad29 (diff)
util/nvmutil: rw_file_exact: check inputs also
we check them in prw, but we used to rely on prw because we called that first. no more. it's correct to also check them here anyway, in case i ever call another function here. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index d9c09bc4..98f5bdcd 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -1888,6 +1888,16 @@ rw_file_exact(int fd, u8 *mem, size_t nrw,
size_t nrw_cur;
void *mem_cur;
+ if (mem == NULL)
+ goto err_rw_file_exact;
+
+ if (fd < 0
+ || off < 0
+ || !nrw /* prevent zero read request */
+ || nrw > (size_t)SSIZE_MAX /* prevent overflow */
+ || (uint)rw_type > IO_PWRITE)
+ goto err_rw_file_exact;
+
while (1) {
/* Prevent theoretical overflow */