Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4529417pxb; Tue, 5 Oct 2021 05:12:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3+HG3mq8zNeH4MD8lJnAcG6UWCWHoHP8Ck0qoH2BC752h8iA6lgO0wYzQFu1gDh2A4Sa1 X-Received: by 2002:a17:906:c1da:: with SMTP id bw26mr24799770ejb.253.1633435930678; Tue, 05 Oct 2021 05:12:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633435930; cv=none; d=google.com; s=arc-20160816; b=Br3LY7nUe/cvFp/5FO2+TwmZvXQ1WyMxtYRDnkFTx3E/qt8AJnojKyBc+fFvYbCsry /L5mlBbMfsY4PjVaiosCZNbNcMOUSrWOBv2l4xZbKLcS9gWiqth6kXcKE3ha3pKn15ps awWgFz8B4IYhbxSlBOV1Ha2TkKBJ33VQTWPmvs7NrvHb9Kvb3gSNr3Od3ieHrn2u7kEq zNErq6RFHKlvWT7Pd4u0mYGh/DgbcE+j7WQlGNrHH5xjGH3nfTRVC+ZN+8WziutEqdIE iI/alSpXvmgGI56ka3NDxR885nFAmCcLgh/C6BHvE4DNIEVYuFoJOx2RQL/Ta/CitSA2 bqeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=P1SScw9fjs5MfeeiQOE2Rg3KWi4HbbSbOi+bA7Wu4iQ=; b=C7WW90H5Jb6I5mYyZ8E25wTocQrexcxR7DU4ZPhnjdHL1g+aO9LahDnnvB+5Yec/zV PvNhZu/ZOlKEOkPNJ6jLpe79qcjEhZk4J8TEChQ+WgGev6Sqo1HZ1QaTYDpKGvXXYFj8 rYKPoJ/33PKZW5eqq4OeeAnaW8wsjVdS1Cp7oLzXOddJsVKFMChtvOBqJ/RBfKPLId5+ dVGWBVW/wUx+nvKFhAjAwSSyJEfLwIgB8S0xj1hevxZ7Xq7k6OjnE6IKfr8HRj//Tsqs nloa/JKT87Ks5Nq/2Xu8oQ+2yARZRrOZoPYpXSE9YvRurN/wEM4L7nsoqLWSLAjdsAFc G9tQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f21si23604743ejj.11.2021.10.05.05.11.44; Tue, 05 Oct 2021 05:12:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234499AbhJEMLj (ORCPT + 99 others); Tue, 5 Oct 2021 08:11:39 -0400 Received: from mga03.intel.com ([134.134.136.65]:52866 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233808AbhJEMLi (ORCPT ); Tue, 5 Oct 2021 08:11:38 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10127"; a="225662756" X-IronPort-AV: E=Sophos;i="5.85,348,1624345200"; d="scan'208";a="225662756" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2021 05:09:47 -0700 X-IronPort-AV: E=Sophos;i="5.85,348,1624345200"; d="scan'208";a="589332377" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2021 05:09:45 -0700 Received: from andy by smile with local (Exim 4.95) (envelope-from ) id 1mXjGR-008sGX-11; Tue, 05 Oct 2021 15:09:43 +0300 Date: Tue, 5 Oct 2021 15:09:43 +0300 From: Andy Shevchenko To: Heiko Carstens 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: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 05, 2021 at 10:54:28AM +0200, Heiko Carstens wrote: > 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: ... > > > > + 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. Yup, so let's convert only the first part then. ... > > > > - 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? Ah, indeed, although it's rather bug in the implementation of above. But original code has it not in use. -- With Best Regards, Andy Shevchenko