summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-14 23:48:27 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-14 23:48:27 +0000
commitcedcb2c68affcbfb94534b823ea2b3562958988e (patch)
tree289892d332650469cfdaca3612299cfcfa2ee225
parent8875a712ae82a041e62ab0b882ee7e27a7f9a7a4 (diff)
util/nvmutil: tidy up io_args
i don't like it grouped together. do it all separate, for clarity. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/nvmutil/nvmutil.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 876d1d44..01024edd 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -2126,14 +2126,28 @@ static int
io_args(int fd, void *mem, size_t nrw,
off_t off, int rw_type)
{
+ /* obviously */
if (mem == NULL)
goto err_io_args;
- if (fd < 0
- || off < 0
- || !nrw /* prevent zero read request */
- || nrw > (size_t)SSIZE_MAX /* prevent overflow */
- || (uint)rw_type > IO_PWRITE)
+ /* uninitialised fd */
+ if (fd < 0)
+ goto err_io_args;
+
+ /* prevent underflow */
+ if (off < 0)
+ goto err_io_args;
+
+ /* prevent zero-byte rw */
+ if (!nrw)
+ goto err_io_args;
+
+ /* prevent overflow */
+ if (nrw > (size_t)SSIZE_MAX)
+ goto err_io_args;
+
+ /* prevent overflow */
+ if (((size_t)off + nrw) < (size_t)off)
goto err_io_args;
return 0;