From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: PATCH: bug fix: infinite loop in sysread
Date: Wed, 5 Feb 2020 22:04:32 +0100 [thread overview]
Message-ID: <CAN=4vMqRooOxw_SZiJjLPD=hkvOVYJXFyVoZKXnwZf5MM+9KjQ@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7aTpOsSMJOoiRnj6mpREfPc8AHJE+Os0FKjuNug23nxMQ@mail.gmail.com>
On Wed, Feb 5, 2020 at 9:55 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Wed, Feb 5, 2020 at 6:20 AM Roman Perepelitsa
> <roman.perepelitsa@gmail.com> wrote:
> >
> > Here select() keeps returning 0, indicating timeout. This is not an
> > error, so errno doesn't get set. If it was EINTR prior to the call,
> > it stays EINTR, and the loop keeps spinning.
> >
> > The fix is to replace `< 1` with `< 0` in the loop condition.
>
> Wouldn't a better fix be to set errno = 0 before the call?
That would be incorrect. select() returns -1 on error and in general
functions must set errno on error and may set it on success. When
select() returns 0, errno can be anything.
Before sending this patch I've also checked if there are similar bugs
in other places. There are none. The result of select() is always
tested with `< 0` everywhere in Zsh expect this one place.
The function I'm modifying has a very similar branch that calls poll()
instead of select. That one compares with `< 0`.
Some quotes:
From `man select`:
On success, select() and pselect() return the number of file
descriptors contained in the three returned descriptor sets
(that is, the total number of bits that are set in readfds,
writefds, exceptfds) which may be zero if the timeout
expires before anything interesting happens. On error, -1
is returned, and errno is set to indicate the error; the
file descriptor sets are unmodified, and timeout becomes
undefined.
From `man errno`:
The value in errno is significant only when the return value
of the call indicated an error (i.e., -1 from most system
calls; -1 or NULL from most library functions); a function
that succeeds is allowed to change errno. The value of
errno is never set to zero by any system call or library
function.
Roman.
next prev parent reply other threads:[~2020-02-05 21:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-05 14:19 Roman Perepelitsa
2020-02-05 20:55 ` Bart Schaefer
2020-02-05 21:04 ` Roman Perepelitsa [this message]
2020-02-06 19:52 ` dana
2020-02-06 20:01 ` Peter Stephenson
2020-02-07 11:26 ` Roman Perepelitsa
2020-02-07 16:49 ` dana
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='CAN=4vMqRooOxw_SZiJjLPD=hkvOVYJXFyVoZKXnwZf5MM+9KjQ@mail.gmail.com' \
--to=roman.perepelitsa@gmail.com \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).