diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-31 15:43:43 +0100 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-31 17:49:23 +0100 |
| commit | d2abde53033d58b6665becd75f854ad87aba33f6 (patch) | |
| tree | b1cd0849ae62dc950f4b07205bf2dadf7bc484aa /util/libreboot-utils/lib/rand.c | |
| parent | c0fd88155a83a0e080eaa769d5035a3c36d6d0fe (diff) | |
libreboot-utils: stricter errno handling
where possible, try not to clobber sys errno. override
it only when relatively safe.
also: when a syscall succeeds, it may set errno. this
is rare, but permitted (nothing specified against it
in specs, and the specs say that errno is undefined
on success).
i'm not libc, but i'm wrapping around it, so i need
to be careful in how i handle the errno value.
also:
i removed the requirement for directories to be
executable, in mkhtemp.c, because this isn't required
and will only break certain setups.
in world_writeable and sticky, i made the checks stricter:
the faccessat check was being skipped on some paths, so
i've closed that loophole now.
i also generally cleaned up some code, as part of the errno
handling refactoring, where it made sense to do so, plus a
few other bits of code cleanup.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils/lib/rand.c')
| -rw-r--r-- | util/libreboot-utils/lib/rand.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c index 20dc33cd..adfad3d7 100644 --- a/util/libreboot-utils/lib/rand.c +++ b/util/libreboot-utils/lib/rand.c @@ -127,6 +127,7 @@ void rset(void *buf, size_t n) { int saved_errno = errno; + errno = 0; if (if_err(buf == NULL, EFAULT)) goto err; @@ -140,7 +141,6 @@ rset(void *buf, size_t n) ((USE_URANDOM) > 0)) arc4random_buf(buf, n); - goto out; #else size_t off = 0; @@ -166,7 +166,7 @@ retry_rand: #endif if (rc < 0) - goto err; + goto err; /* syscall fehler */ if (rc == 0) goto err; /* prevent infinite loop on fatal err */ @@ -180,16 +180,15 @@ retry_rand: #endif #endif -out: - errno = saved_errno; + reset_caller_errno(0); return; err: #if defined(USE_URANDOM) && \ ((USE_URANDOM) > 0) close_on_eintr(&fd); #endif - err_exit(ECANCELED, - "Randomisation failure, possibly unsupported in your kernel"); + (void) with_fallback_errno(ECANCELED); + err_exit(errno, "Randomisierungsfehler"); exit(EXIT_FAILURE); } #endif |
