[PATCH v2 05/25] linux: Add fallback for 64-bit time_t SO_{RCV, SND}TIMEO

Florian Weimer fweimer@redhat.com
Thu May 20 06:44:41 GMT 2021


* Adhemerval Zanella via Libc-alpha:

> +#ifndef __ASSUME_TIME64_SYSCALLS
> +static int
> +getsockopt32 (int fd, int level, int optname, void *optval,
> +	      socklen_t *len)
> +{
> +  int r = -1;
> +
> +  if (level != SOL_SOCKET)
> +    return r;
> +
> +  switch (optname)
> +    {
> +    case COMPAT_SO_RCVTIMEO_NEW:
> +    case COMPAT_SO_SNDTIMEO_NEW:
> +      {
> +        if (*len < sizeof (struct __timeval64))
> +	  {
> +	    __set_errno (EINVAL);
> +	    break;
> +	  }
> +
> +	if (optname == COMPAT_SO_RCVTIMEO_NEW)
> +	  optname = COMPAT_SO_RCVTIMEO_OLD;
> +	if (optname == COMPAT_SO_SNDTIMEO_NEW)
> +	  optname = COMPAT_SO_SNDTIMEO_OLD;
> +
> +	struct __timeval32 tv32;
> +	r = getsockopt_syscall (fd, level, optname, &tv32,
> +				(socklen_t[]) { sizeof tv32 });
> +	if (r < 0)
> +	  break;
> +	struct __timeval64 *tv64 = (struct __timeval64 *) optval;
> +	*tv64 = valid_timeval32_to_timeval64 (tv32);
> +	*len = sizeof (*tv64);
> +      }

I think POSIX requires checking the incoming *len value and truncating
the output.

Thanks,
Florian



More information about the Libc-alpha mailing list