From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from edna.lautre.net (edna.lautre.net [80.67.160.88]) by sourceware.org (Postfix) with ESMTPS id 296FF3858D3C for ; Mon, 14 Feb 2022 18:10:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 296FF3858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nonadev.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nonadev.net Received: from d-jobol.iot.bzh (por56-1-78-229-206-229.fbx.proxad.net [78.229.206.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by edna.lautre.net (Postfix) with ESMTPSA id A5D37106564; Mon, 14 Feb 2022 19:10:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=nonadev.net; s=alternc; t=1644862228; bh=h31rJEwRtI2l6Wp/eA8vSIGQ0lPxCeegOPJ7yYHtwGw=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=HT5BzJEegtUba1q/w/kCBKBDqcEE2Aws/fJGR+cDhN0PMR45mR7S53r3CdUxNyF1Z 72Glhc+OhH0A+D2y5JvYj2FQxXjJXY2ILrnndaeWe4QV3solHfPrg9ISpQkyNM1lA0 qIXHBujgKOap4ACtqx8XxB/LD9M/8YYEBdgr1JNs= Date: Mon, 14 Feb 2022 19:10:18 +0100 From: =?UTF-8?B?Sm9zw6k=?= Bollo To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] libio: Ensure output buffer for wchars (bug 28828) Message-ID: <20220214191018.64bc4b69@d-jobol.iot.bzh> In-Reply-To: <391bad58-2186-93db-c1bc-663e7fbe6345@linaro.org> References: <391bad58-2186-93db-c1bc-663e7fbe6345@linaro.org> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Feb 2022 18:10:31 -0000 On Mon, 14 Feb 2022 11:15:46 -0300 Adhemerval Zanella wrote: > On 13/02/2022 16:52, jobol@nonadev.net wrote: > > When fileops.c checks for nullity of the write pointer, > > in order to ensure its allocation, before that patch, > > wfileops didn't. This was leading to crashes on some cases, > > as described by bug 28828. > >=20 > > The minimal sequence to produce the crash was: > >=20 > > =C2=A0=C2=A0=C2=A0 #include > > =C2=A0=C2=A0=C2=A0 #include > > =C2=A0=C2=A0=C2=A0 int main(int ac, char **av) > > =C2=A0=C2=A0=C2=A0 { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 setv= buf(stdout, NULL, _IOLBF, 0); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fget= wc(stdin); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fput= wc(10, stdout); /*CRASH HERE!*/ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 retu= rn 0; > > =C2=A0=C2=A0=C2=A0 } > >=20 > > The line "fgetwc(stdin);" is necessary. It introduces the > > bug by setting the flag _IO_CURRENTLY_PUTTING of stdout > > indirectly (file wfileops.c, function _IO_wfile_underflow, line > > 213). > >=20 > > Signed-off-by: Jose Bollo =20 >=20 > Patch looks ok, but git-pw fails to apply it: >=20 > $ git-pw patch apply 51088 > Applying: libio: Ensure output buffer for wchars (bug 28828) > error: patch failed: libio/wfileops.c:412 > error: libio/wfileops.c: patch does not apply > error: Did you hand edit your patch? I copied the ouput of [git format-patch], following as much as possible https://sourceware.org/glibc/wiki/Contribution%20checklist but didn't used [git send-email]. I don't have the command [git pw] that you are using. I can see that [git apply] produce the same issue but [git am] perfectly works. > Could you resend it?=20 I can try but maybe you have a hint avoiding me to do the same... > Also, could you also provide a regression testcase for this fix? Why not. Where? a libio/bug-XXX.c ? > > --- > > =C2=A0libio/wfileops.c | 5 +++-- > > =C2=A01 file changed, 3 insertions(+), 2 deletions(-) > >=20 > > diff --git a/libio/wfileops.c b/libio/wfileops.c > > index fb9d45b677..aa94a22983 100644 > > --- a/libio/wfileops.c > > +++ b/libio/wfileops.c > > @@ -412,10 +412,11 @@ _IO_wfile_overflow (FILE *f, wint_t wch) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return WEOF; > > =C2=A0=C2=A0=C2=A0=C2=A0 } > > =C2=A0=C2=A0 /* If currently reading or no buffer allocated. */ > > -=C2=A0 if ((f->_flags & _IO_CURRENTLY_PUTTING) =3D=3D 0) > > +=C2=A0 if ((f->_flags & _IO_CURRENTLY_PUTTING) =3D=3D 0 > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 || f->_wide_data->_IO_write_base =3D=3D= NULL) > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Allocate a buffer if needed. */ > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (f->_wide_data->_IO_write_base =3D= =3D 0) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (f->_wide_data->_IO_write_base =3D= =3D NULL) > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 _IO_wdoallocbuf (f); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 _IO_free_wbackup_area (f); =20