From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
Andreas Schwab <schwab@suse.de>
Subject: Re: [PATCH v2 1/2] linux: Normalize and return timeout on select (BZ #27651)
Date: Fri, 09 Apr 2021 14:38:54 +0200 [thread overview]
Message-ID: <87czv3y6n5.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20210409113639.1124756-1-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Fri, 9 Apr 2021 08:36:38 -0300")
* Adhemerval Zanella via Libc-alpha:
> +/* Return true if select modify the timeout to reflect the amount of time
> + no slept. */
> +extern bool support_select_modify_timeout (void);
> +
> +/* Return true if select normalize the timeout input by taking in account
> + tv_usec larger than 1000000. */
> +extern bool support_select_normalize_timeout (void);
Maybe use support_select_modifies_timeout and
support_select_normalizes_timeout?
Please commit the support/ bits separately.
> diff --git a/sysdeps/unix/sysv/linux/select.c b/sysdeps/unix/sysv/linux/select.c
> index 415aa87d3c..d075270ff4 100644
> --- a/sysdeps/unix/sysv/linux/select.c
> +++ b/sysdeps/unix/sysv/linux/select.c
> @@ -33,12 +33,34 @@ int
> __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
> struct __timeval64 *timeout)
> {
> + __time64_t s = timeout != NULL ? timeout->tv_sec : 0;
> + int32_t us = timeout != NULL ? timeout->tv_usec : 0;
> + int32_t ns;
> +
> + if (s < 0 || us < 0)
> + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
> +
> + /* Normalize the timeout, as legacy Linux __NR_select and __NR__newselect.
> + Different than syscall, it also handle possible overflow. */
> + if (us / USEC_PER_SEC > INT64_MAX - s)
> {
> + s = INT64_MAX;
> + ns = NSEC_PER_SEC - 1;
> }
> + else
> + {
> + s += us / USEC_PER_SEC;
> + us = us % USEC_PER_SEC;
> + ns = us * NSEC_PER_USEC;
> + }
> +
> + struct __timespec64 ts64, *pts64 = NULL;
> + if (timeout != NULL)
> + {
> + ts64.tv_sec = s;
> + ts64.tv_nsec = ns;
> + pts64 = &ts64;
> + }
The overflow handling is slightly inconsistent with the in_time_t_range
range check below. Here we use silently saturating arithmetic, below
it's an error.
Thanks,
Florian
next prev parent reply other threads:[~2021-04-09 12:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-09 11:36 Adhemerval Zanella
2021-04-09 11:36 ` [PATCH v2 2/2] linux: always update select timeout (BZ #27706) Adhemerval Zanella
2021-04-09 12:26 ` Florian Weimer
2021-04-09 12:38 ` Florian Weimer [this message]
2021-04-09 12:46 ` [PATCH v2 1/2] linux: Normalize and return timeout on select (BZ #27651) Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87czv3y6n5.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
--cc=schwab@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).