Compare commits

...

6 Commits

Author SHA1 Message Date
Leah Rowe
fbe2986a6e util/nvmutil: r_type check in rw_gbe_file_part
i already send the right arg anyway. this is a
preventative bug fix against future maintenance.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 13:15:00 +00:00
Leah Rowe
847f63be87 util/nvmutil: remove pointless check
already checked below, then err()

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 06:20:30 +00:00
Leah Rowe
62131ec093 util/nvmutil: add missing cast
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 06:18:29 +00:00
Leah Rowe
ebac61df5e util/nvmutil: err in rw_file_exact on zero return
zero never occurs, because rw_file_once never returns zero,
but only rw_file_once determines that. rw_file_exact must
handle every possible error.

right now, if that call returns zero, rw_file_exact would
have an infinite loop.

this doesn't actually happen at the moment, so this is a
preventative bug fix.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 06:05:54 +00:00
Leah Rowe
cbf409d6e1 util/nvmutil: increment rc at end of rw_file_exact
for fussy static analysers and/or compilers

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 05:51:48 +00:00
Leah Rowe
2ecee50da8 util/nvmutil: further tidy up prw()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-13 05:43:49 +00:00

View File

@@ -1456,7 +1456,11 @@ rw_gbe_file_part(size_t p, int rw_type,
uint8_t *mem_offset;
if (rw_type == IO_WRITE || rw_type == IO_PWRITE)
if (rw_type < IO_PREAD || rw_type > IO_PWRITE)
err(errno, "%s: %s: part %lu: invalid rw_type, %d",
fname, rw_type_str, (unsigned long)p, rw_type);
if (rw_type == IO_PWRITE)
invert = 0;
/*
@@ -1564,9 +1568,11 @@ rw_file_exact(int fd, uint8_t *mem, size_t len,
return -1;
}
for (rc = 0, rv = 0; rc < len; rc += (size_t)rv) {
if ((rv = rw_file_once(fd, mem, len, off, rw_type, rc)) == -1)
for (rc = 0, rv = 0; rc < len; ) {
if ((rv = rw_file_once(fd, mem, len, off, rw_type, rc)) <= 0)
return -1;
rc += (size_t)rv;
}
return rc;
@@ -1615,9 +1621,6 @@ static ssize_t
do_rw(int fd, uint8_t *mem,
size_t len, off_t off, int rw_type)
{
if ((unsigned int)rw_type > IO_PWRITE)
goto err_do_rw;
if (rw_type == IO_READ)
return read(fd, mem, len);
@@ -1627,7 +1630,6 @@ do_rw(int fd, uint8_t *mem,
if (rw_type == IO_PREAD || rw_type == IO_PWRITE)
return prw(fd, mem, len, off, rw_type);
err_do_rw:
errno = EIO;
return -1;
}
@@ -1648,8 +1650,11 @@ prw(int fd, void *mem, size_t nrw,
off_t off_orig;
ssize_t r;
int saved_errno;
int prw_type;
if ((unsigned int)(rw_type ^ IO_PREAD) > IO_WRITE) {
prw_type = rw_type ^ IO_PREAD;
if ((unsigned int)prw_type > IO_WRITE) {
errno = EIO;
return -1;
}
@@ -1660,7 +1665,7 @@ prw(int fd, void *mem, size_t nrw,
return -1;
do {
r = do_rw(fd, mem, nrw, off, rw_type ^ IO_PREAD);
r = do_rw(fd, mem, nrw, off, prw_type);
} while (r < 0 && errno == EINTR);
saved_errno = errno;