From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from brown.elm.relay.mailchannels.net (brown.elm.relay.mailchannels.net [23.83.212.23]) by sourceware.org (Postfix) with ESMTPS id A0C783858415 for ; Tue, 15 Feb 2022 13:52:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0C783858415 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 28C7A4C0CD5; Tue, 15 Feb 2022 13:52:28 +0000 (UTC) Received: from pdx1-sub0-mail-a307.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 3824F4C0BA3; Tue, 15 Feb 2022 13:52:27 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a307.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.112.55.226 (trex/6.5.3); Tue, 15 Feb 2022 13:52:28 +0000 X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Quick-Quick: 0c9a19c04ee31f77_1644933147507_2709089080 X-MC-Loop-Signature: 1644933147507:249415308 X-MC-Ingress-Time: 1644933147507 Received: from [192.168.1.174] (unknown [1.186.123.170]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a307.dreamhost.com (Postfix) with ESMTPSA id 4JyjFj3lVLz1K4; Tue, 15 Feb 2022 05:52:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gotplt.org; s=gotplt.org; t=1644933146; bh=DK3eqC3aFn1W3d/KDrC/8MBN1Jw=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=KJLpfHfhwpYISwadwjoimwvqSk8lPCFTNgrjTjeqVRvb5TLbcO0jumfqIfbZN6C2a f2ahOF7DDW+cw2JMFxIWI+exqmIo97Bo+8WkN0rPsvELBjHqbcwSQckef3zFbzIvmZ 5oPDe5IGA2mT6I//LLZaeTSacoFzrF0/bGzSaBi0= Message-ID: <068fb737-d440-4d73-a1c2-a8daab41c25d@gotplt.org> Date: Tue, 15 Feb 2022 19:22:19 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v1] String: Strength memset tests in test-memset.c Content-Language: en-US To: Noah Goldstein , libc-alpha@sourceware.org References: <20220214014037.2422450-1-goldstein.w.n@gmail.com> From: Siddhesh Poyarekar In-Reply-To: <20220214014037.2422450-1-goldstein.w.n@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3037.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL, SPF_HELO_NONE, SPF_PASS, TXREP, 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: Tue, 15 Feb 2022 13:52:33 -0000 On 14/02/2022 07:10, Noah Goldstein via Libc-alpha wrote: > The prior sentinel logic was broken and was checking the SIMPLE_MEMSET > as opposed to the tested implementation. As well `s` (the test buffer) > was not reset between implementation tests so it was possible for a > buggy implementation to be hidden by a previously executed correct > one. > --- > string/test-memset.c | 36 +++++++++++++++++++++--------------- > 1 file changed, 21 insertions(+), 15 deletions(-) > > diff --git a/string/test-memset.c b/string/test-memset.c > index 8498b1bc97..ee548f6924 100644 > --- a/string/test-memset.c > +++ b/string/test-memset.c > @@ -106,26 +106,28 @@ SIMPLE_MEMSET (CHAR *s, int c, size_t n) > } > > static void > -do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n) > +do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n, int space_below, int space_above) > { > - CHAR buf[n + 2]; > - CHAR *tstbuf = buf + 1; > - CHAR sentinel = c - 1; > - buf[0] = sentinel; > - buf[n + 1] = sentinel; > + CHAR buf[n]; > + CHAR sentinel = ~c; > + if (space_below) > + s[-1] = sentinel; > + if (space_above) > + s[n] = sentinel; > + SIMPLE_MEMSET(s, ~c, n); Setting s with ~c... > #ifdef TEST_BZERO > - simple_bzero (tstbuf, n); > + simple_bzero (buf, n); > CALL (impl, s, n); > - if (memcmp (s, tstbuf, n) != 0 > - || buf[0] != sentinel > - || buf[n + 1] != sentinel) > + if (memcmp (s, buf, n) != 0 > + || (space_below && s[-1] != sentinel) > + || (space_above && s[n] != sentinel)) > #else > CHAR *res = CALL (impl, s, c, n); ... and then overwriting it with c... > if (res != s > - || SIMPLE_MEMSET (tstbuf, c, n) != tstbuf > - || MEMCMP (s, tstbuf, n) != 0 > - || buf[0] != sentinel > - || buf[n + 1] != sentinel) > + || SIMPLE_MEMSET (buf, c, n) != buf > + || MEMCMP (s, buf, n) != 0 ... which should then equate to buf since it is also set to c. OK. > + || (space_below && s[-1] != sentinel) > + || (space_above && s[n] != sentinel)) > #endif /* !TEST_BZERO */ > { > error (0, 0, "Wrong result in function %s", impl->name); > @@ -137,12 +139,16 @@ do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n) > static void > do_test (size_t align, int c, size_t len) > { > + int space_below, space_above; > align &= 4095; > if ((align + len) * sizeof (CHAR) > page_size) > return; > > + space_below = !!align; > + space_above = !((align + len + 1) * sizeof (CHAR) > page_size); > + > FOR_EACH_IMPL (impl, 0) > - do_one_test (impl, (CHAR *) (buf1) + align, c, len); > + do_one_test (impl, (CHAR *) (buf1) + align, c, len, space_below, space_above); This would reduce test coverage, testing underflow only in cases where align is non-zero. Couldn't this be fixed without this coverage reduction? Thanks, Siddhesh