summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-14 17:45:06 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-26 06:59:41 +0000
commitb86f415a3e82ffaa08dca4f4006f7cf8c0dfe982 (patch)
treed68643b7beb8837218a39077b78738aea0a3092f
parentd34552b400aaacdbc3760d57a4c59a8206972bed (diff)
util/nvmutil: check regular file in rw_file_exact
Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/nvmutil/nvmutil.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index d605ac79..00f45db3 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -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;
}
/*