From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 87A57385ED40; Thu, 27 Jan 2022 17:09:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 87A57385ED40 Received: by mail-pl1-x633.google.com with SMTP id c9so2994623plg.11; Thu, 27 Jan 2022 09:09:50 -0800 (PST) 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=4k/lbnXBqYEXs0/vOtpV3T0xxnAgrebtl1yQ7G205gE=; b=YzA6cNumvCrDtbOuaSTK4cFqfQ0w/L81WMZ+bHujZgxPjgBTG9Mg71/enIB4QS69O+ 5t/l1ZJPlx+ZlOuzKfLQ8T3Jk1X53pxMNkUBqGoHNMw62qw7p/Lzs0fCrrwQCG1zC1mo KJUNDQAwnP8PdisrOx40+M9VrmY2jewblgGxThymLGncwTmI5rYXpyBPvO3BdrHkentA 6U0Mqynm/A/ckw10uv6Y2EI33AbicYQLlkwzpJgj9AAe5Tsk/1GkCec4t4tWCmuBeFw9 k4YrcFIRp8Q/2dgszPB5XvZbWowIjPEZ3OpT9T48r9ZzZ4goIqGg6UtRLEqW/r1e13k8 rJpA== X-Gm-Message-State: AOAM531aZuQolRrxlsj0JeCXVWs/sa+P+9iQklMDx5V/v0lfIZ+7DB+I C+pAetylSVxAspFYVDbt72EGVpzInL0g10XqlFFLZ+Fr X-Google-Smtp-Source: ABdhPJxnRadRoDELEMau/krA3JhtaY/6z4fgLF2RynTsyBGvuoub2dJs4IVXVDdP7LR5MYmlHucgpDnsevT6WqtsZZ0= X-Received: by 2002:a17:903:2350:: with SMTP id c16mr4367488plh.4.1643303389680; Thu, 27 Jan 2022 09:09:49 -0800 (PST) MIME-Version: 1.0 References: <20210327162449.3215538-1-hjl.tools@gmail.com> <87ft0g8oz4.fsf@mid.deneb.enyo.de> <871rc08mym.fsf@mid.deneb.enyo.de> In-Reply-To: <871rc08mym.fsf@mid.deneb.enyo.de> From: "H.J. Lu" Date: Thu, 27 Jan 2022 09:09:14 -0800 Message-ID: Subject: Re: [PATCH v2] test-strnlen.c: Check that strnlen won't go beyond the maximum length To: Florian Weimer , Libc-stable Mailing List Cc: "H.J. Lu via Libc-alpha" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3027.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jan 2022 17:09:54 -0000 On Sat, Mar 27, 2021 at 11:34 AM Florian Weimer wrote: > > * 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. I am backporting this to release branches. -- H.J.