From 632c85ce1cbfc4b8c651c0bb258805fa657a747a Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Tue, 10 Mar 2026 11:06:31 +0000 Subject: util/nvmutil: restore errno if lseek resets it if it resets it on success, that is! theoretically possible. we must preserve errno. normally i'm a bit more casual about it, but this function is replicating libc, so i must be strict Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 64ef5bec..28368f8d 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1371,6 +1371,7 @@ prw(int fd, void *mem, size_t count, { off_t old; ssize_t r; + int restore_errno; int saved_errno = 0; if ((old = lseek_eintr(fd, (off_t)0, SEEK_CUR)) == (off_t)-1) @@ -1391,9 +1392,13 @@ prw(int fd, void *mem, size_t count, if (r < 0) saved_errno = errno; + restore_errno = errno; + if (lseek_eintr(fd, old, SEEK_SET) == (off_t)-1) { if (saved_errno) errno = saved_errno; + else + errno = restore_errno; return -1; } -- cgit v1.2.1