From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 18a8df39 for ; Wed, 5 Feb 2020 21:05:25 +0000 (UTC) Received: (qmail 5160 invoked by alias); 5 Feb 2020 21:05:20 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45384 Received: (qmail 4575 invoked by uid 1010); 5 Feb 2020 21:05:20 -0000 X-Qmail-Scanner-Diagnostics: from mail-il1-f174.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25713. spamassassin: 3.4.2. Clear:RC:0(209.85.166.174):SA:0(-2.0/5.0):. Processed in 3.809969 secs); 05 Feb 2020 21:05:20 -0000 X-Envelope-From: roman.perepelitsa@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.166.174 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fcQF+bzanjoecJGuqKUeWWCGTqiRqJGB/kK7UlKddkc=; b=CAXWJaeUSavD2LMAVS/uJgW1E8dbivUukO66D+hdhhBhAH/n0ULSTZkBzrWImTwh8/ PncW4Q3Ju7Bo6O2E63BZVFNjAv6GvpO64Vo2gg4sbGifnEgvFak6eTm9g1w+WjhOcLbL isiIdDzbFY7XofNa85umwnFinXWFP2hv6wgyLalPK8HaMi9UcnYJBMsR/vkjlB/C8jTP RkFq6sgiR4dwyLHh81Vm6YJNoH3x4lBEwHrDCvBeY+6fnmJnb9ykZTA/3yP5uqC+JX8D qKoyC7aw9mMYZU1wNml5xcANaytbI9ZiWV1K2ofDdkNaBW8m6HhH/FZDoTbjH+8CzcCM 8m8g== X-Gm-Message-State: APjAAAWzRagjAhh0IZ98HCboYrm8z32nBvQw+W09g0wsW51dVRMnSHfG 8QxZhzZdDKkXulcK6KeBfJFFPgBC6zwfnazz7Lt9LQWyYi4= X-Google-Smtp-Source: APXvYqyfyJXwsYBbElqlIjPDHoaQylM+RKxTAqPq8eK7650LMYVH4bGcFwsb09BOxIEFCPzeBLImP4s2T26Js1Z8kZw= X-Received: by 2002:a92:d642:: with SMTP id x2mr71281ilp.169.1580936683713; Wed, 05 Feb 2020 13:04:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Wed, 5 Feb 2020 22:04:32 +0100 Message-ID: Subject: Re: PATCH: bug fix: infinite loop in sysread To: Bart Schaefer Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" On Wed, Feb 5, 2020 at 9:55 PM Bart Schaefer wrote: > > On Wed, Feb 5, 2020 at 6:20 AM Roman Perepelitsa > 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.