From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from black.elm.relay.mailchannels.net (black.elm.relay.mailchannels.net [23.83.212.19]) by sourceware.org (Postfix) with ESMTPS id 5AF1D398A86B for ; Wed, 9 Jun 2021 06:48:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5AF1D398A86B 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 B0EA3701D6A; Wed, 9 Jun 2021 06:48:05 +0000 (UTC) Received: from pdx1-sub0-mail-a10.g.dreamhost.com (100-101-162-59.trex.outbound.svc.cluster.local [100.101.162.59]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 4C6E0701E03; Wed, 9 Jun 2021 06:48:05 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a10.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.101.162.59 (trex/6.3.1); Wed, 09 Jun 2021 06:48:05 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Irritate-Grain: 0bdc854b6fab1321_1623221285580_3319903094 X-MC-Loop-Signature: 1623221285580:3461118558 X-MC-Ingress-Time: 1623221285580 Received: from pdx1-sub0-mail-a10.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTP id F3C547EFCF; Tue, 8 Jun 2021 23:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gotplt.org; h=subject:to :cc:references:from:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; s=gotplt.org; bh=Kqwx08 5BjyM8tfFjDG/n+7GpcUQ=; b=ZYcSaT4CycvImSK2gZWT78Ckpq+T+L2AklrqNX F5gk3gz1KbokQuTCQRalcIoNbOXwIKnAlxRgpvaUFVcCzDoBcSCXCkPDkZIDt6SO uNll+dENZg/y8BjCHbBTBpYLvTdKGhp3HxPBZC8F4qTTY+9pyHWUU1kspyii6RiZ XS4LM= Received: from [192.168.1.126] (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTPSA id 102037E669; Tue, 8 Jun 2021 23:48:02 -0700 (PDT) Subject: Re: [PATCH v1] x86: memcmp-avx2-movbe.S and memcmp-evex-movbe.S fix overflow bug. To: Noah Goldstein Cc: Paul Eggert , GNU C Library References: <20210607083011.855616-1-goldstein.w.n@gmail.com> <8690911e-3cac-836b-2a8a-8b5b2ca74b02@cs.ucla.edu> <263a051d-8807-64b6-989e-f1ee3d03055a@gotplt.org> <87ea4f71-3b06-1259-5663-ce8a8db72279@gotplt.org> X-DH-BACKEND: pdx1-sub0-mail-a10 From: Siddhesh Poyarekar Message-ID: <00e3f10b-9769-306e-7391-b57bd48a1476@gotplt.org> Date: Wed, 9 Jun 2021 12:17:57 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3029.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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: Wed, 09 Jun 2021 06:48:08 -0000 On 6/9/21 12:02 PM, Noah Goldstein wrote: > Wait are you saying that the return value overflowing causes UB or > that the act of passing a maxlen where s=C2=A0+ maxlen * sizeof(wchar_t= ) is > outside range object is UB? Not specifically the return value, but more broadly, causing wcsnlen to=20 invoke undefined behaviour, which could include the former. > If the former then why is the follow okay: >=20 > Previous example with a string whose length is 1000 > but because wcslen is passed maxlen where maxlen * sizeof(wchar_t) > overflows and leads to a result less than 1000 the implementation of > wcslen in wcsnlen-avx2.S will return a length less than 1000. >=20 >=20 > If the latter then: >=20 > For test-wcsnlen=C2=A0which redirects to test-strnlen > If the UB is when is s+maxlen*sizeof(wchar_t) is outside object bound > then s=C2=A0+ SIZE_MAX=C2=A0+ sizeof(wchar_t) surely is. >=20 > Although even then test-strnlen s=C2=A0+ SIZE_MAX will also overflow if= s non=20 > null. That is a good catch; I did not notice that. That should be SIZE_MAX /=20 sizeof (CHAR). Thanks, Siddhesh