mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-03-27 06:19:03 +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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user