From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>,
Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Cc: Andreas Schwab <schwab@suse.de>
Subject: Re: [PATCH v2 1/2] linux: Normalize and return timeout on select (BZ #27651)
Date: Fri, 9 Apr 2021 09:46:10 -0300 [thread overview]
Message-ID: <f1eded87-9d05-d144-bddd-39ead185822c@linaro.org> (raw)
In-Reply-To: <87czv3y6n5.fsf@oldenburg.str.redhat.com>
On 09/04/2021 09:38, Florian Weimer wrote:
> * 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.
In fact on the in_time_t below it needs to check for the normalized
tv_sec on ts64.tv_sec instead of the input timeout. I will fix it
and send a newer version without the libsupport bits.
prev parent reply other threads:[~2021-04-09 12:46 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 ` [PATCH v2 1/2] linux: Normalize and return timeout on select (BZ #27651) Florian Weimer
2021-04-09 12:46 ` Adhemerval Zanella [this message]
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=f1eded87-9d05-d144-bddd-39ead185822c@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--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).