From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by sourceware.org (Postfix) with ESMTPS id 867693858D33 for ; Tue, 6 Jun 2023 12:20:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 867693858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 7C04A3C2FA8; Tue, 6 Jun 2023 12:20:09 +0000 (UTC) Received: from pdx1-sub0-mail-a232.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 0C0D33C2E56; Tue, 6 Jun 2023 12:20:09 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686054009; a=rsa-sha256; cv=none; b=Jtqf5Ef0euKyHpnihdfAt+2lIX01iDWinUiNfRDJaFpTN8YJLHJHZCyhdMgbAZWLgfD9Sa Hc1jdwZjVF8+KUjQ5IZT5QeFZ0Eg+RYag4gEepC5x9vBVZlDKKy7+pOYHQ+YBBbn2rso4p d13zzjPRpTqIvpJu73OAlt0n0fOWE8vhf/AKAuA5rQkQ77WFi5cjzo3ZmOZjhvw1xlRA2c zyRSTozUTy2aVHbKp5KI5oaIA3v+39gfFFzk+kWmSw2jt1MPz9w1KW7aevu22h0641oG94 61HBReYvfOn+yDEH02cAcmrMNlhNE+bxqYVndFOLlqcOxdhfeUVQk0/1JPXXtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686054009; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3tFsKgFheFkbnWXzCKNmFKiS9CAhiBnCNWokidxdFO8=; b=LudA/QqZqKyPqpDwH94k9Wy+CSA0O8ADlR/5tOTL2TMdGpz/Ii0lMNJXpSV8dMWBaYXyuD YPiAQ45/M13v+wa0fr0DMtfFiwPUlwymlcXocYfFdMmqaHbiIJVQ39xSD27x2jcBICRezK Fod9haQ/N4Eh+tgDzkQByvsf+/RksEIV0Fn1Gr5j0e/n66OcnNiak0pzffQJsvy+Utg3vn u0AMDQRemRKcyB4YM1DhEPQT7v0Ym2YWYlUyNhM65s/XxLHECcKWaemyxDa5ezfgWnVzdL IE5MFqUL3noSJ1EX/i4sku0RxfseNVzQWoEh7fPEIl6w4zGVLBnOy7GdKBaCiQ== ARC-Authentication-Results: i=1; rspamd-5f966895c-gjlpx; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Supply-Broad: 375a8e12525c3015_1686054009305_1206051342 X-MC-Loop-Signature: 1686054009304:349627476 X-MC-Ingress-Time: 1686054009304 Received: from pdx1-sub0-mail-a232.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.123.193.172 (trex/6.8.1); Tue, 06 Jun 2023 12:20:09 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-02-142-113-138-85.dsl.bell.ca [142.113.138.85]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a232.dreamhost.com (Postfix) with ESMTPSA id 4Qb8gX4MhPzb9; Tue, 6 Jun 2023 05:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1686054008; bh=3tFsKgFheFkbnWXzCKNmFKiS9CAhiBnCNWokidxdFO8=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=Cyj3XSE7bDdlwg5fwQ9+XU0sqoWa7nIgvY/CbyD3TrMskYKwNQFOKipqeu8rG/50n E+eB+sd86quuUXVMGFRQ7DjuxMe1tkOVId1A/osqpzJaiFhSEiTjY8b30vgMuG2fh2 w7NvRNL2biCOb0La6c5GQc42+FOPiqJCiL6DxZto1bChsGXBPlPK4TlwaAoDqF5XVv At4XztoQoVL3O6WJ0Pc0fs/giuecXAc3dfKPUPBAHYFpUNmTRvNa9jRQD3ULea7jpQ Je0qCU44cLyuEYAcdK4zVzMSY2uItpuZp2lT1zLujYom7JKthNH+9hpulKzqvj5a+i W1OY1wFlCAiAQ== Message-ID: <199ef217-6acb-5e85-a5a3-5dfa6db6823d@gotplt.org> Date: Tue, 6 Jun 2023 08:20:07 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v6 5/7] tests: replace fgets by xfgets Content-Language: en-US To: =?UTF-8?B?RnLDqWTDqXJpYyBCw6lyYXQ=?= , libc-alpha@sourceware.org References: <20230602152812.108497-1-fberat@redhat.com> <20230602152812.108497-6-fberat@redhat.com> From: Siddhesh Poyarekar In-Reply-To: <20230602152812.108497-6-fberat@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3037.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-06-02 11:28, Frédéric Bérat wrote: > With fortification enabled, fgets calls return result needs to be checked, > has it gets the __wur macro enabled. > --- > Changes since v4/v5: > - Rebased > > assert/test-assert-perr.c | 8 +++++--- > assert/test-assert.c | 8 +++++--- > stdio-common/test_rdwr.c | 11 ++++------- > support/Makefile | 1 + > support/xfgets.c | 32 ++++++++++++++++++++++++++++++++ > support/xstdio.h | 1 + > sysdeps/pthread/tst-cancel6.c | 3 ++- > 7 files changed, 50 insertions(+), 14 deletions(-) > create mode 100644 support/xfgets.c > > diff --git a/assert/test-assert-perr.c b/assert/test-assert-perr.c > index 8496db6ffd..09a4fcb6ef 100644 > --- a/assert/test-assert-perr.c > +++ b/assert/test-assert-perr.c > @@ -11,6 +11,8 @@ > #include > #include > > +#include > + > jmp_buf rec; > char buf[160]; > > @@ -70,15 +72,15 @@ main(void) > failed = 1; /* should not happen */ > > rewind (stderr); > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (!strstr(buf, strerror (1))) > failed = 1; > > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (strstr (buf, strerror (0))) > failed = 1; > > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (strstr (buf, strerror (2))) > failed = 1; > > diff --git a/assert/test-assert.c b/assert/test-assert.c > index 26b58d4dd3..25e264543b 100644 > --- a/assert/test-assert.c > +++ b/assert/test-assert.c > @@ -11,6 +11,8 @@ > #include > #include > > +#include > + > jmp_buf rec; > char buf[160]; > > @@ -72,15 +74,15 @@ main (void) > failed = 1; /* should not happen */ > > rewind (stderr); > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (!strstr (buf, "1 == 2")) > failed = 1; > > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (strstr (buf, "1 == 1")) > failed = 1; > > - fgets (buf, 160, stderr); > + xfgets (buf, 160, stderr); > if (strstr (buf, "2 == 3")) > failed = 1; > > diff --git a/stdio-common/test_rdwr.c b/stdio-common/test_rdwr.c > index 7825ca9358..0544916eb1 100644 > --- a/stdio-common/test_rdwr.c > +++ b/stdio-common/test_rdwr.c > @@ -20,6 +20,7 @@ > #include > #include > > +#include > > int > main (int argc, char **argv) > @@ -49,7 +50,7 @@ main (int argc, char **argv) > > (void) fputs (hello, f); > rewind (f); > - (void) fgets (buf, sizeof (buf), f); > + xfgets (buf, sizeof (buf), f); > rewind (f); > (void) fputs (buf, f); > rewind (f); > @@ -104,12 +105,8 @@ main (int argc, char **argv) > if (!lose) > { > rewind (f); > - if (fgets (buf, sizeof (buf), f) == NULL) > - { > - printf ("fgets got %s.\n", strerror(errno)); > - lose = 1; > - } > - else if (strcmp (buf, replace)) > + xfgets (buf, sizeof (buf), f); > + if (strcmp (buf, replace)) > { > printf ("Read \"%s\" instead of \"%s\".\n", buf, replace); > lose = 1; > diff --git a/support/Makefile b/support/Makefile > index 3eed2deb1a..bbd3465d04 100644 > --- a/support/Makefile > +++ b/support/Makefile > @@ -123,6 +123,7 @@ libsupport-routines = \ > xdup2 \ > xfchmod \ > xfclose \ > + xfgets \ > xfopen \ > xfork \ > xfreopen \ > diff --git a/support/xfgets.c b/support/xfgets.c > new file mode 100644 > index 0000000000..e2db19cf53 > --- /dev/null > +++ b/support/xfgets.c > @@ -0,0 +1,32 @@ > +/* fgets with error checking. > + Copyright (C) 2016-2023 Free Software Foundation, Inc. Only 2023. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > + > +#include > +#include > + > +char * > +xfgets (char *s, int size, FILE *stream) > +{ > + char *ret = fgets (s, size, stream); > + if (!ret && ferror(stream)) > + FAIL_EXIT1 ("fgets failed: %m"); > + > + return ret; > +} > diff --git a/support/xstdio.h b/support/xstdio.h > index 633c342c82..f30bee6a20 100644 > --- a/support/xstdio.h > +++ b/support/xstdio.h > @@ -28,6 +28,7 @@ FILE *xfopen (const char *path, const char *mode); > void xfclose (FILE *); > FILE *xfreopen (const char *path, const char *mode, FILE *stream); > void xfread (void *ptr, size_t size, size_t nmemb, FILE *stream); > +char *xfgets (char *s, int size, FILE *stream); > > /* Read a line from FP, using getline. *BUFFER must be NULL, or a > heap-allocated pointer of *LENGTH bytes. Return the number of > diff --git a/sysdeps/pthread/tst-cancel6.c b/sysdeps/pthread/tst-cancel6.c > index 63e6d49707..49b7399353 100644 > --- a/sysdeps/pthread/tst-cancel6.c > +++ b/sysdeps/pthread/tst-cancel6.c > @@ -20,12 +20,13 @@ > #include > #include > > +#include > > static void * > tf (void *arg) > { > char buf[100]; > - fgets (buf, sizeof (buf), arg); > + xfgets (buf, sizeof (buf), arg); > /* This call should never return. */ > return NULL; > }