[PATCH] malloc: Do not clobber errno on __getrandom_nocancel (BZ#29624)

Yann Droneaud ydroneaud@opteya.com
Thu Sep 29 17:46:39 GMT 2022


Hi,

29 septembre 2022 à 18:45 "Adhemerval Zanella via Libc-alpha" a écrit:

> Use INTERNAL_SYSCALL_CALL instead of INLINE_SYSCALL_CALL. This
> requires emulate the semantic for hurd call (so __arc4random_buf
> uses the fallback).
> 
> Checked on x86_64-linux-gnu.
> ---
>  stdlib/arc4random.c | 4 ++--
>  sysdeps/mach/hurd/not-cancel.h | 11 +++++++++--
>  sysdeps/unix/sysv/linux/not-cancel.h | 2 +-
>  3 files changed, 12 insertions(+), 5 deletions(-)

[...] 

> diff --git a/sysdeps/mach/hurd/not-cancel.h b/sysdeps/mach/hurd/not-cancel.h
> index ae58b734e3..f2cb9b60ba 100644
> --- a/sysdeps/mach/hurd/not-cancel.h
> +++ b/sysdeps/mach/hurd/not-cancel.h
> @@ -75,8 +76,14 @@ __typeof (__fcntl) __fcntl_nocancel;
>  #define __fcntl64_nocancel(...) \
>  __fcntl_nocancel (__VA_ARGS__)
>  
> -#define __getrandom_nocancel(buf, size, flags) \
> - __getrandom (buf, size, flags)
> +static inline int
> +__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags)
> +{
> + int save_errno = errno;
> + int r = __getrandom (buf, buflen, flags);
> + __set_errno (save_errno);
> + return r == -1 ? -save_errno : r;
> +}
>  

I don't get why the saved errno value is returned.


Regards.

-- 
Yann Droneaud
OPTEYA


More information about the Libc-alpha mailing list