From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cichlid.ash.relay.mailchannels.net (cichlid.ash.relay.mailchannels.net [23.83.222.36]) by sourceware.org (Postfix) with ESMTPS id 7C71C3858406 for ; Mon, 13 Jun 2022 06:31:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7C71C3858406 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 5FA891211BD; Mon, 13 Jun 2022 06:31:52 +0000 (UTC) Received: from pdx1-sub0-mail-a306.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C08FA1221E1; Mon, 13 Jun 2022 06:31:36 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1655101911; a=rsa-sha256; cv=none; b=TM9wFEw+9ZPpgjH7pRFYE1u3UgKNp3Umk/zGbqVqtnQ2dJjPY2fm0HIB4ittXy3wim2PY8 6BNCTlomLfaFyrYAGie1tfUyl0l7PZ2ncqcnlgBxd+SNQ7A6AMWPAixDq/Z3jVNCk+Yo2p R54wSmL29H1Jc1qK/4+Z1dmvfXf23zxlxHBUTcTSyPruxC60olEAxRio4fQqcJFhgVQeGs 0+Fsf6zqCAzwHDLcDqE+EVhVGc1bnOgdW1FmY3cw+WoKfAQ8waKBPgtxlSHcS+IHHhhTQB s7sUp3j2rnZpMr2V6egAG/Njmb3sN7plOjlWIHmC2K9wXC/57qsD42NPRpkfrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1655101911; 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=6yikcJJaTULGQDRIyYUNfvNdaOJfnAhLcaQ4uxTVlIA=; b=WdXNKrTWP80VN+47GZiJ4ko5HNWisNrioK12MwMIVG3T066kXhySCtzwqJ3q8XWYxvrnER CS4bQXxdnT3FA42YhszjcMiXXEA+dN2Ni2QNPDbD/R+9WS3YaosDhxXLiGpFns+KzmRko9 4wv9DVdwpYUakbNDpNHoEroaMhtIe22OtjUx2kqUpDd+lomBbsSQc9cBy3Y/OBJa1idXjz mN80SvOgW48GUo0vo4+dyeTCiz8sgKNVcM7ApEjIK2KIG6LrEgY8OHCIetTOiLcivy/57K J9pB9/hmqY8EKYhLoKBSfQlIe75Ilkx+Gb7prZnpBWj1/iQhMhK2Qu/O86UpMQ== ARC-Authentication-Results: i=1; rspamd-786f5898df-99b68; 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-Hook-Power: 0384b4891fc048cc_1655101912221_2208659618 X-MC-Loop-Signature: 1655101912221:1793030151 X-MC-Ingress-Time: 1655101912221 Received: from pdx1-sub0-mail-a306.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.124.238.94 (trex/6.7.1); Mon, 13 Jun 2022 06:31:52 +0000 Received: from [100.96.149.178] (unknown [49.248.235.144]) (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-a306.dreamhost.com (Postfix) with ESMTPSA id 4LM1tJ50byzCT; Sun, 12 Jun 2022 23:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1655101881; bh=6yikcJJaTULGQDRIyYUNfvNdaOJfnAhLcaQ4uxTVlIA=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=vA70Wu/RxJFILdAdUaBrPI3gWW281RTSTcpA4h0QEWELz31BC53du/Z0IT3oyT9Ot fkflYggt1910CTQEtJZmJ2Q0LMbk+I7yh60OiV0gN/G7j0bxTMwgaUCIK11c17zn+k XOJhXKPuXfZ+AwpsRJCaPy84fpinAiDrH+pFJZ0w0qmQH5Ap30ADgFD67zxHmQHx+B L60RXNFu6na13wRZdIhEbS4sk1xi2OhOcu5nzmJVXawx44EOZ1P39mD3B5M1ZddHAm WXzmlc+0Px+2i+aMOyp84Rut+/D7kf0xMuDiYcH9k/SXs3ahMgWKAiiPUC9HbuiN+a g0aQ1L1uiZ5eg== Message-ID: <8abe7126-cf1d-821e-4f87-e55c2b32526b@gotplt.org> Date: Mon, 13 Jun 2022 12:01:17 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] Avoid -Wstringop-overflow= warning in iconv module. Content-Language: en-US To: Stefan Liebler , libc-alpha@sourceware.org References: <20220603125251.3903158-1-stli@linux.ibm.com> From: Siddhesh Poyarekar In-Reply-To: <20220603125251.3903158-1-stli@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3038.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, 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 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: Mon, 13 Jun 2022 06:32:01 -0000 On 03/06/2022 18:22, Stefan Liebler via Libc-alpha wrote: > On s390x when compiling with GCC 12, I get this warning: > utf8-utf16-z9.c: > ../iconv/loop.c: In function ‘__from_utf8_loop_etf3eh_single’: > ../iconv/loop.c:445:22: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=] > 445 | bytebuf[inlen++] = *inptr++; > | ~~~~~~~~~~~~~~~~~^~~~~~~~~~ > ../iconv/loop.c:381:17: note: at offset 4 into destination object ‘bytebuf’ of size 4 > 381 | unsigned char bytebuf[MAX_NEEDED_INPUT]; > | ^~~~~~~ > ../iconv/loop.c:445:22: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=] > 445 | bytebuf[inlen++] = *inptr++; > | ~~~~~~~~~~~~~~~~~^~~~~~~~~~ > ../iconv/loop.c:381:17: note: at offset 5 into destination object ‘bytebuf’ of size 4 > 381 | unsigned char bytebuf[MAX_NEEDED_INPUT]; > | ^~~~~~~ > > This patch tells the compiler that inend is always behind inptr which > avoids the warning. Note that the SINGLE function is only used to > implement the mb*towc*() or wc*tomb*() functions. Those functions use > inptr and inend pointing to a variable on stack, compute the inend pointer > or explicitly check the arguments which always leads to inptr < inend. LGTM; there was a time that this wasn't true for applications that assumed POSIX behaviour in wcrtomb but it is true now. See also: commit 9bcd12d223a8990254b65e2dada54faa5d2742f3 Author: Siddhesh Poyarekar Date: Fri May 13 19:10:15 2022 +0530 wcrtomb: Make behavior POSIX compliant Please add a note in the git commit log that if someone wants to backport this patch to release branches, they should also backport this wcrtomb change. Reviewed-by: Siddhesh Poyarekar > --- > iconv/loop.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/iconv/loop.c b/iconv/loop.c > index f8727a637a..09ade3b765 100644 > --- a/iconv/loop.c > +++ b/iconv/loop.c > @@ -435,11 +435,17 @@ SINGLE(LOOPFCT) (struct __gconv_step *step, > return __GCONV_FULL_OUTPUT; > > /* Now add characters from the normal input buffer. */ > - if (inlen >= MAX_NEEDED_INPUT) > + if (inlen >= MAX_NEEDED_INPUT || inptr >= inend) > /* Avoid a -Wstringop-overflow= warning when this loop is > unrolled. The compiler cannot otherwise see that this is > unreachable because it depends on (state->__count & 7) not > - being too large after a previous conversion step. */ > + being too large after a previous conversion step. > + Starting with GCC 12, we also have mark the inptr >= inend > + case as unreachable to omit the warning. Note that this SINGLE > + function is only used to implement the mb*towc*() or wc*tomb*() > + functions. Those functions use inptr and inend pointing to a > + variable on stack, compute the inend pointer or explicitly check > + the arguments which always leads to inptr < inend. */ > __builtin_unreachable (); > do > bytebuf[inlen++] = *inptr++;