From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28397 invoked from network); 25 Oct 2021 19:42:25 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 25 Oct 2021 19:42:25 -0000 Received: (qmail 13917 invoked by uid 550); 25 Oct 2021 19:42:22 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 19820 invoked from network); 25 Oct 2021 18:13:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iciuyVzGVY7oThh4SORMrt6HeFsmdij6QW0BZwerwY4=; b=PZ2UU5oP2qzO8BN79JO5bUIQ1M0J5d+/0Z85PH5EG4fS46JDD29ZEmasImbTZMq/wH c5zjxDEw07s5LvihzIP8qHDMwB1xBq842iT89ijP+zSjBXkmEV8rKPy3C+x/Jab2QMmY GYnFObzBpVktSmi+oNU3IA/m2U7v9v2BBahFJeUESnCXTOWdQdGJgL/vKo554mwH2SRJ dDImW1NEtQ+r9+c+WM0xTwMVx0Lo2AYpTCcYr6IVongzjO1kPOyWt/xS/6a/8uazuRhI ETVd8jEJRXvjvNSeZ0bK/VPPL42Cz3eIY5CxqGMnxxrjvmUDAvc8BRyAyP5i//q2JKWw eoiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iciuyVzGVY7oThh4SORMrt6HeFsmdij6QW0BZwerwY4=; b=dHZg17eBRqOXiRvU5++qd3g6MgyaQmZFMiY1Pcl+wjmF4sp73y02QGBRH3r01Yd2S6 4xMzakXHNzkjP4GBoFWM06VbTotJmQkETBoQoQMQogBDubzT+HVuRM/nBPbwh1jWiY2o pgs8nIgwxewRpFSqUzeVKOgjZSfY/j3baCTMKGgDWlsNEj9sMuN4lzxlVDAF2leE7qoI YsKakgVCrnI4gJlaAiGaWWCcTv2cW5suIri0LOyZ1FMabm44O3hkwrKoXehL68Vv68UE ahNWvYi3V2fcjQ2XUJ7Tw9nD/QPNig7bHDmSRmfiHI0NVgDlFrnu81OBvzE1wQ2IF+Pn FSaA== X-Gm-Message-State: AOAM533GV2GD4+OGldED9jvj5oh63U4/+plCvAi/EPreeDXrfLsHBnkz dkq9h/+Bq0qFpmflTm4pImh6AgbDFRFdLcxJnkwn0FM= X-Google-Smtp-Source: ABdhPJx6old1O4zi3ctv8XByvUUsxBHmF/Dlr6oH1VpHAwehEmjUItZbtJWxUIHnLK0wvj99vSA6BgDtADffjTj7r7w= X-Received: by 2002:a2e:b16e:: with SMTP id a14mr20837641ljm.274.1635185610942; Mon, 25 Oct 2021 11:13:30 -0700 (PDT) MIME-Version: 1.0 References: <20211025172557.GT7074@brightrain.aerifal.cx> In-Reply-To: <20211025172557.GT7074@brightrain.aerifal.cx> From: Lorenzo Beretta Date: Mon, 25 Oct 2021 20:13:20 +0200 Message-ID: To: Rich Felker Cc: musl@lists.openwall.com Content-Type: multipart/alternative; boundary="0000000000007b6a0705cf31510e" Subject: Re: [musl] Re: request: please detect reads from stdin with unflushed --0000000000007b6a0705cf31510e Content-Type: text/plain; charset="UTF-8" I was thinking something like a warning on stderr fwiw, but I guess you're right, I didn't consider multithreading. Thank you for the detailed reply. Il giorno lun 25 ott 2021 alle ore 19:25 Rich Felker ha scritto: > On Mon, Oct 25, 2021 at 03:17:13PM +0200, Lorenzo Beretta wrote: > > > Suggestion: fix those broken programs! > > > > I know, I know... the problem is that they work with glibc and they fail > > silently with musl, and on top of that I've just discovered that at least > > netbsd and openbsd do the same as glibc, ie a broken program like > > #include > > int main(){ > > printf("not flushed: "); > > char line[123]; > > return fgets(line,sizeof line,stdin) ? 0 : 123; > > } > > > > happens to work!!! > > > > What I'm asking is that musl (while technically correct!) helps > > __detecting__ those programs, possibly as an option ("#ifdef > > HUMOR_BROKEN_PROGRAMS") > > > > PS > > I'm not subscribed to this mailing list, sorry for not mentioning it the > > first time > > There's nothing detectable here because there's nothing wrong with the > program; the bug is in the programmer's *expectation* that the output > be visible. > > It's possible to implement the behavior the programmer here desired, > the optional flushing of line-buffered output streams before reading > input. This would not help detect the bug in expectaions though; it > would just help mask it. The reason this behavior is not present in > musl is because it does not scale with significant numbers of stdio > streams open, and can even produce deadlock conditions in > multithreaded programs where there is no semantic deadlock but the > additional flushing produces an extraneous operation on a stream in a > way that causes deadlock. > > If you hit a program with an issue like this, it should be fairly easy > to fix by adding fflush(stdout) or fflush(0) immediately before the > relevant input operations. > > Rich > --0000000000007b6a0705cf31510e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I was thinking something like a warning on stderr fwiw, bu= t I guess you're right, I didn't consider multithreading.
Thank= you for the detailed reply.

Il giorno lun 25 ott 2021 alle ore 19:25 = Rich Felker <dalias@libc.org> = ha scritto:
On M= on, Oct 25, 2021 at 03:17:13PM +0200, Lorenzo Beretta wrote:
> > Suggestion: fix those broken programs!
>
> I know, I know... the problem is that they work with glibc and they fa= il
> silently with musl, and on top of that I've just discovered that a= t least
> netbsd and openbsd do the same as glibc, ie a broken program like
> #include <stdio.h>
> int main(){
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("not flushed: "); >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0char line[123];
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return fgets(line,sizeof line,stdin) = ? 0 : 123;
> }
>
> happens to work!!!
>
> What I'm asking is that musl (while technically correct!) helps > __detecting__ those programs, possibly as an option ("#ifdef
> HUMOR_BROKEN_PROGRAMS")
>
> PS
> I'm not subscribed to this mailing list, sorry for not mentioning = it the
> first time

There's nothing detectable here because there's nothing wrong with = the
program; the bug is in the programmer's *expectation* that the output be visible.

It's possible to implement the behavior the programmer here desired, the optional flushing of line-buffered output streams before reading
input. This would not help detect the bug in expectaions though; it
would just help mask it. The reason this behavior is not present in
musl is because it does not scale with significant numbers of stdio
streams open, and can even produce deadlock conditions in
multithreaded programs where there is no semantic deadlock but the
additional flushing produces an extraneous operation on a stream in a
way that causes deadlock.

If you hit a program with an issue like this, it should be fairly easy
to fix by adding fflush(stdout) or fflush(0) immediately before the
relevant input operations.

Rich
--0000000000007b6a0705cf31510e--