Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4388392pxb; Tue, 5 Oct 2021 01:56:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWt6q0ut3w4Hxg0cvCQjQvypqm8BAY0kq7JCZeyaR6aG+qmBsP0rm41u2QVwQGfL54Wrts X-Received: by 2002:a05:6402:544:: with SMTP id i4mr25248460edx.349.1633424181691; Tue, 05 Oct 2021 01:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633424181; cv=none; d=google.com; s=arc-20160816; b=e2UUq3ZXpSPvT11/WUjKa9jjqoeY4p8eo/dgassDR6CXb/6GrU4p7KaXtOxNT6FpB/ Ege3B3p8LeaJk2UOdTS+RXPO17MYW1HKTnQgspImcf1YYDcjarZzuO3gF+nyM2n2M/VW xC76jSjuKaC+R7AObmzObcuDN82rymv8FDE3OHD9kn3puoO1M1Ypnsrs+92i995SY9MO J+P5Hpz92X2+alg0UN4Ox7o5o04xNYv19Jy41muXWr9F1GrQjf+9OnNbFEqMj5hijQ9F 5CzTkDWpx8i/0UcNWoutCZPx/s75ACnTW2omG6N3rKU0ON94FehW6wMF0KieQZByic0p xZpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Oc3GvTQfzksAh7Ij8tpg94WjZ7As1pYxcRGBnzkR4T8=; b=SV5O3Z3fEMp1aGitrke87lawgo8qqE6TWBExTz3s/MdPpwaAhVtbLfTVJlJjT+WF0U 3y6gsVy/wGGW6AZyKC/GzwynWa9fCnYUbCIj0jimTRaap2VZbs7f2OcT87bKAhEmffhP dU437IDrB02emjJcowy8L07jPNiwE9gOeoPjuB1qExuoTTbTCOTssq4zxb26+iVnfIq+ Mvx75N41hHkzdS1UZ/nXIrhYmSRsmzNOZhRwGvlq1xSUssAkOxzomStCaR7ErD94hs9A bbn6txoYv8A8Mx1Py/xNBPXHrFa3PnKVqh9rTDrA7fs8QqSBxMI6h/KBK27+3M+HjEXJ 1eNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=dLgwPOut; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e14si15368854edj.549.2021.10.05.01.55.58; Tue, 05 Oct 2021 01:56:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=dLgwPOut; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233077AbhJEI43 (ORCPT + 99 others); Tue, 5 Oct 2021 04:56:29 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38010 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232739AbhJEI42 (ORCPT ); Tue, 5 Oct 2021 04:56:28 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1958g3Qw024789; Tue, 5 Oct 2021 04:54:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=Oc3GvTQfzksAh7Ij8tpg94WjZ7As1pYxcRGBnzkR4T8=; b=dLgwPOutMeYkpMw37ClaXMEdDAhlIkT/sBzRFGJZP/hZwpKBXQEi2lK30JibLFAYXFfd a20t5DNCIjFefY1fj0Ve/fZSkSBBtFQcRnWEyfqKbqOnja0EikWUC+8ul8sdstrBnsLQ RkGtIjgZB6/Qx1wri6zKsCbmpQugUN1nLDIOH8dklslG3Q2/AY3MfNV5XCcG53r6IX6H VPseOXWo6UbTrB0welEAvKKBLF1yeS5nZ4Le7SiBUMrFdcaLw70z8EMkfyYr/7If7qK2 kFUjDQC/4fN0SarBd6IJQqXgHDD5jKVpmaPy6PsTVY2+VPiKX5kOTsu5mPrRynBAiJtU jA== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 3bgkdw86h2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Oct 2021 04:54:36 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1958mWCG020471; Tue, 5 Oct 2021 08:54:34 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 3beepjg740-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Oct 2021 08:54:34 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1958sUrU38994194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Oct 2021 08:54:30 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A5A4152065; Tue, 5 Oct 2021 08:54:30 +0000 (GMT) Received: from osiris (unknown [9.145.46.219]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 64D205205F; Tue, 5 Oct 2021 08:54:30 +0000 (GMT) Date: Tue, 5 Oct 2021 10:54:28 +0200 From: Heiko Carstens To: Andy Shevchenko Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Vasily Gorbik , Christian Borntraeger Subject: Re: [PATCH v1 1/1] s390: Use string_upper() instead of open coded variant Message-ID: References: <20211001130201.72545-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: cPPcssBzOwyyeEHkFO6Sgkp5Pyo4XnJf X-Proofpoint-GUID: cPPcssBzOwyyeEHkFO6Sgkp5Pyo4XnJf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-10-04_05,2021-10-04_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 bulkscore=0 suspectscore=0 impostorscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110050049 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 05, 2021 at 11:18:38AM +0300, Andy Shevchenko wrote: > On Mon, Oct 04, 2021 at 10:31:46PM +0200, Heiko Carstens wrote: > > On Fri, Oct 01, 2021 at 04:02:01PM +0300, Andy Shevchenko wrote: > > > + /* Segment name is limited by 8 characters + NUL */ > > > + char tmp[8 + 1]; > > > int i; > > > > > > - for (i = 0; i < 8; i++) { > > > - if (name[i] == '\0') > > > - break; > > > - dcss_name[i] = toupper(name[i]); > > > - } > > > - for (; i < 8; i++) > > > - dcss_name[i] = ' '; > > > + /* > > > + * This snprintf() call does two things: > > > + * - makes a NUL-terminated copy of the input string > > > + * - pads it with spaces > > > + */ > > > + snprintf(tmp, sizeof(tmp), "%s ", name); > > > > I can't say I like code where I have to count spaces in order to > > verify if the code is actually correct. > > I understand your point, but have any idea how to make it differently > and not ugly at the same time? Don't know. You could use strncopy+strlen+memset (with space character). After all I'm not very convinced that the resulting code buys us anything compared to the current variant. > > > + string_upper(dcss_name, tmp); > > ... > > > > static struct dcss_segment * > > > segment_by_name (char *name) > > > { > > > - char dcss_name[9]; > > > + char dcss_name[8]; > > > > string_upper will copy the terminating NUL-byte. By reducing the size > > of dcss_name to 8 bytes this will result in stack corruption. > > Nope. Even in the original code this additional byte is left unused. I'm talking about the new code, not the old code: If "name" points to a NUL terminated eight chararacter string, then the new code will use snprintf to copy it 1:1 to tmp, and the subsequent string_upper() will copy the string (upper cased) to dcss_name, now including the NUL terminating byte, which won't fit into dcss_name. Am I missing something here?