util/nvmutil: check regular file in rw_file_exact

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-14 17:45:06 +00:00
parent 94b89beef9
commit 276b9d34e8

View File

@@ -1831,9 +1831,21 @@ rw_file_exact(int fd, u8 *mem, size_t nrw,
off_t off, int rw_type, int loop_eagain,
int loop_eintr, size_t max_retries)
{
struct stat st;
ssize_t rv;
size_t rc;
/* Programs like cat can use this,
so we only check if it's a normal
file if not looping EAGAIN */
if (!loop_eagain) {
if (fstat(fd, &st) == -1)
goto err_rw_file_exact;
if (S_ISREG(st.st_mode))
goto err_rw_file_exact;
}
for (rc = 0, rv = 0; rc < nrw; ) {
if ((rv = rw_file_once(fd, mem, nrw, off, rw_type, rc,
loop_eagain, loop_eintr, max_retries)) < 0)
@@ -1852,6 +1864,10 @@ rw_file_exact(int fd, u8 *mem, size_t nrw,
}
return rc;
err_rw_file_exact:
errno = EIO;
return -1;
}
/*