From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 625E7386F82F for ; Fri, 26 Jun 2020 07:53:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 625E7386F82F Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05Q7qHJh177323 for ; Fri, 26 Jun 2020 03:53:02 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 31uwypjwpe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 26 Jun 2020 03:53:00 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05Q7ov0g030630 for ; Fri, 26 Jun 2020 07:52:54 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 31uus72sby-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 26 Jun 2020 07:52:54 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05Q7qqDh30212162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 26 Jun 2020 07:52:52 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DA12A4054 for ; Fri, 26 Jun 2020 07:52:52 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C840A405F for ; Fri, 26 Jun 2020 07:52:52 +0000 (GMT) Received: from oc4452167425.ibm.com (unknown [9.145.169.110]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Fri, 26 Jun 2020 07:52:52 +0000 (GMT) Subject: Re: [PATCH] Fix stringop-overflow errors from gcc 10 in iconv. To: GNU C Library References: <20200616122420.5175-1-stli@linux.ibm.com> From: Stefan Liebler Message-ID: <95a04f2f-19d8-ab0b-19f5-448930fc4b13@linux.ibm.com> Date: Fri, 26 Jun 2020 09:52:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200616122420.5175-1-stli@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-26_04:2020-06-26, 2020-06-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 impostorscore=0 spamscore=0 bulkscore=0 cotscore=-2147483648 mlxscore=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006260054 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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: Fri, 26 Jun 2020 07:53:03 -0000 ping On 6/16/20 2:24 PM, Stefan Liebler wrote: > On s390x, I've recognize various -Werror=stringop-overflow messages > in iconv/loop.c and iconv/skeleton.c if build with gcc10 -O3. > > With this commit gcc knows the size and do not raise those errors anymore. > --- > iconv/loop.c | 14 ++++++++------ > iconv/skeleton.c | 8 +++++--- > 2 files changed, 13 insertions(+), 9 deletions(-) > > diff --git a/iconv/loop.c b/iconv/loop.c > index 9f7570d591..b032fcd9ac 100644 > --- a/iconv/loop.c > +++ b/iconv/loop.c > @@ -420,8 +420,10 @@ SINGLE(LOOPFCT) (struct __gconv_step *step, > # else > /* We don't have enough input for another complete input > character. */ > - while (inptr < inend) > - state->__value.__wchb[inlen++] = *inptr++; > + size_t inlen_after = inlen + (inend - inptr); > + assert (inlen_after <= sizeof (state->__value.__wchb)); > + for (; inlen < inlen_after; inlen++) > + state->__value.__wchb[inlen] = *inptr++; > # endif > > return __GCONV_INCOMPLETE_INPUT; > @@ -483,11 +485,11 @@ SINGLE(LOOPFCT) (struct __gconv_step *step, > /* We don't have enough input for another complete input > character. */ > assert (inend - inptr > (state->__count & ~7)); > - assert (inend - inptr <= sizeof (state->__value)); > + assert (inend - inptr <= sizeof (state->__value.__wchb)); > state->__count = (state->__count & ~7) | (inend - inptr); > - inlen = 0; > - while (inptr < inend) > - state->__value.__wchb[inlen++] = *inptr++; > + for (inlen = 0; inlen < inend - inptr; inlen++) > + state->__value.__wchb[inlen] = inptr[inlen]; > + inptr = inend; > # endif > } > > diff --git a/iconv/skeleton.c b/iconv/skeleton.c > index 1dc642e2fc..1a38b51a5a 100644 > --- a/iconv/skeleton.c > +++ b/iconv/skeleton.c > @@ -795,11 +795,13 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data, > # else > /* Make sure the remaining bytes fit into the state objects > buffer. */ > - assert (inend - *inptrp < 4); > + size_t cnt_after = inend - *inptrp; > + assert (cnt_after <= sizeof (data->__statep->__value.__wchb)); > > size_t cnt; > - for (cnt = 0; *inptrp < inend; ++cnt) > - data->__statep->__value.__wchb[cnt] = *(*inptrp)++; > + for (cnt = 0; cnt < cnt_after; ++cnt) > + data->__statep->__value.__wchb[cnt] = (*inptrp)[cnt]; > + *inptrp = inend; > data->__statep->__count &= ~7; > data->__statep->__count |= cnt; > # endif >