From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from albireo.enyo.de (albireo.enyo.de [37.24.231.21]) by sourceware.org (Postfix) with ESMTPS id 7375D385801A for ; Sat, 27 Mar 2021 18:34:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7375D385801A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=deneb.enyo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fw@deneb.enyo.de Received: from [172.17.203.2] (port=43343 helo=deneb.enyo.de) by albireo.enyo.de ([172.17.140.2]) with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1lQDli-00040i-1J; Sat, 27 Mar 2021 18:34:42 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1lQDlh-00062s-Tn; Sat, 27 Mar 2021 19:34:41 +0100 From: Florian Weimer To: "H.J. Lu via Libc-alpha" Subject: Re: [PATCH v2] test-strnlen.c: Check that strnlen won't go beyond the maximum length References: <20210327162449.3215538-1-hjl.tools@gmail.com> <87ft0g8oz4.fsf@mid.deneb.enyo.de> Date: Sat, 27 Mar 2021 19:34:41 +0100 In-Reply-To: (H. J. Lu via Libc-alpha's message of "Sat, 27 Mar 2021 11:09:32 -0700") Message-ID: <871rc08mym.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Sat, 27 Mar 2021 18:34:44 -0000 * H. J. Lu via Libc-alpha: > From: "H.J. Lu" > Date: Sat, 27 Mar 2021 09:06:39 -0700 > Subject: [PATCH v2] test-strnlen.c: Check that strnlen won't go beyond the > maximum length > > Place strings ending at page boundary without the null byte. If an > implementation goes beyond EXP_LEN, it will trigger the segfault. > --- > string/test-strnlen.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/string/test-strnlen.c b/string/test-strnlen.c > index 0293acbc71..d70faa26ab 100644 > --- a/string/test-strnlen.c > +++ b/string/test-strnlen.c > @@ -198,6 +198,35 @@ do_page_tests (void) > } > } > > +/* Tests meant to unveil fail on implementations that access bytes > + beyond the maxium length. */ > + > +static void > +do_page_2_tests (void) > +{ > + size_t i, exp_len, offset; > + size_t last_offset = page_size / sizeof (CHAR); > + > + CHAR *s = (CHAR *) buf2; > + MEMSET (s, 65, last_offset); > + > + /* Place short strings ending at page boundary without the null > + byte. */ > + offset = last_offset; > + for (i = 0; i < 128; i++) > + { > + /* Decrease offset to stress several sizes and alignments. */ > + offset--; > + exp_len = last_offset - offset; > + FOR_EACH_IMPL (impl, 0) > + { > + /* If an implementation goes beyond EXP_LEN, it will trigger > + the segfault. */ > + do_one_test (impl, (CHAR *) (s + offset), exp_len, exp_len); > + } > + } > +} Thanks, looks good. The comments and the commit message are much clearer now.