[PATCH v2] malloc: Do not clobber errno on __getrandom_nocancel (BZ#29624)
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Thu Sep 29 18:36:54 GMT 2022
Hi Adhemerval,
Another question, the syscall is defined as:
ssize_t getrandom (void *__buffer, size_t __length,
Doesn't this mean if we use 'int' for the return value, a large but valid syscall
result could be interpreted as a negative error value? It sounds like all code
processing the getrandom syscall should use ssize_t rather than int. Or do we
limit length to something fairly small?
__arc4random_buf (void *p, size_t n)
{
static int seen_initialized;
- size_t l;
+ int l;
Should be ssize_t?
+static inline int
+__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags)
ssize_t?
+{
+ int save_errno = errno;
+ int r = __getrandom (buf, buflen, flags);
ssize_t?
+ r = r == -1 ? -errno : r;
+ __set_errno (save_errno);
+ return r;
+}
#define __poll_infinity_nocancel(fds, nfds) \
__poll (fds, nfds, -1)
diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
index a263d294b1..00ab75a405 100644
--- a/sysdeps/unix/sysv/linux/not-cancel.h
+++ b/sysdeps/unix/sysv/linux/not-cancel.h
@@ -71,7 +71,7 @@ __writev_nocancel_nostatus (int fd, const struct iovec *iov, int iovcnt)
static inline int
ssize_t?
__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags)
{
- return INLINE_SYSCALL_CALL (getrandom, buf, buflen, flags);
+ return INTERNAL_SYSCALL_CALL (getrandom, buf, buflen, flags);
}
Cheers,
Wilco
More information about the Libc-alpha
mailing list