mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-15 08:20:59 +02:00
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>
This commit is contained in:
+19
-5
@@ -2126,14 +2126,28 @@ static int
|
|||||||
io_args(int fd, void *mem, size_t nrw,
|
io_args(int fd, void *mem, size_t nrw,
|
||||||
off_t off, int rw_type)
|
off_t off, int rw_type)
|
||||||
{
|
{
|
||||||
|
/* obviously */
|
||||||
if (mem == NULL)
|
if (mem == NULL)
|
||||||
goto err_io_args;
|
goto err_io_args;
|
||||||
|
|
||||||
if (fd < 0
|
/* uninitialised fd */
|
||||||
|| off < 0
|
if (fd < 0)
|
||||||
|| !nrw /* prevent zero read request */
|
goto err_io_args;
|
||||||
|| nrw > (size_t)SSIZE_MAX /* prevent overflow */
|
|
||||||
|| (uint)rw_type > IO_PWRITE)
|
/* 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;
|
goto err_io_args;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user