Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp6282770pxb; Thu, 27 Jan 2022 10:13:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxf1XJpo33tL/9fvGxhe9Idb7IP0HrGaX0xqOx8SBisYLHhjVjNqAP36sZRRiuaPHVtmQV X-Received: by 2002:a17:906:7316:: with SMTP id di22mr3875969ejc.505.1643307210089; Thu, 27 Jan 2022 10:13:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643307210; cv=none; d=google.com; s=arc-20160816; b=C+TZR/9bmsDRpnzXoK8wep6bbOGKJWGYvCPj8hFWEXEFwtXPm7iK+ln7TTn5rIZzdp fCw4CJ3REf38CQp44BF4JdycuSotxUhPrb6/mbfg8RanPnJYSf00uaOyXMgH2kmE3+Py DAPlj9EP1OWdqRkYSJRtIGB6N7WgluBTsykklEXf1SohHU05eUCfQA+qxcDrmNkm64Qo n0IHQ67/inzDBfezIgI2HeHtgeQEQCbzND8T2i4RAsY+ao8hXpjXquSlQTrIixI3RRmF 2wYEdHUfUFYHrXRHSARVgdU+YLQhno5Ega0lgdhIp0wsGKaQMUGvzcrX+xBhJj8nnsOu Nsfg== 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=gazJ0IjDWYn6JR5Fe02lIm0FuIqc00XSsrdL4KDPqWA=; b=B4Fjw8dhasQOnCV0nuApsFIlJZtSXuhIuwfti4O7HE+xV/k6NGsJmx5SJwlSUDIo89 LnRffNXRla4Ts5jqiGCVKtRo53E8LDtz2cNTbJLcUCLcWlnSpfMgtuAZLrpxqUsWbXb5 LysHaCd6BJA5KXYw2kmLGL5sGOCWH6TuWVv5hjB5HFX6oBLa8s3+I+1EqqqeWhgMSIdT pnQB2JmuDs6tX0g7fLVmsA8RUcd+a41HUTpTqyosExzbmMO251OgTMpnfrrUWuTMMH3z b3Lzp6OjwDGmugO5KDf7jgXxlhlkIsRb79FrNss0p7NQqNpk5NxtjwkBk5Ab9g1RUSbe gfVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="l3/d7f5D"; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr16si1747717ejc.565.2022.01.27.10.13.04; Thu, 27 Jan 2022 10:13:30 -0800 (PST) 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=@intel.com header.s=Intel header.b="l3/d7f5D"; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239950AbiA0LEY (ORCPT + 99 others); Thu, 27 Jan 2022 06:04:24 -0500 Received: from mga07.intel.com ([134.134.136.100]:60950 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239942AbiA0LEV (ORCPT ); Thu, 27 Jan 2022 06:04:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643281461; x=1674817461; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=2VvT1Bjef2duRgl2x3XRoAHuY+VVE3Ni6AYhrZqmo9w=; b=l3/d7f5D2mStHNOHCnOhIeFyppm+GNklvwXBxaK2h1HJV6PJDXWeR3z7 mslDzDWbwctraF0OkwHbEYsUjOEUPrLDe1eignxaU0FESkaOk5ttMuiGL qvR8KJ5xM3rjNcdLHVRlDrx5Qhf0uzVyHAws/PQndgHWVrBV/ApNyxmSY i3hUaYHQXxITbeNL3UZOoxJFWIBfrph1GYKQyz5Y0YwcQcWvlRxcDmrv3 OlUdHjGp3SmFXUETyiDdveRGFcn/IJWvuwQ5YuRAIIBhrVwoQUQxpZ0Zx wn/0kkuRR1jb4WwEz6y16thLePjdvdV7HHeHxI0AgYuMCLLC333IMDgig Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10239"; a="310132124" X-IronPort-AV: E=Sophos;i="5.88,320,1635231600"; d="scan'208";a="310132124" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 03:04:07 -0800 X-IronPort-AV: E=Sophos;i="5.88,320,1635231600"; d="scan'208";a="696601420" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 03:04:05 -0800 Received: from paasikivi.fi.intel.com (localhost [127.0.0.1]) by paasikivi.fi.intel.com (Postfix) with SMTP id E3463202F2; Thu, 27 Jan 2022 13:04:02 +0200 (EET) Date: Thu, 27 Jan 2022 13:04:02 +0200 From: Sakari Ailus To: Kees Cook Cc: Andy Shevchenko , Francis Laniel , Petr Mladek , linux-kernel@vger.kernel.org, Andy Shevchenko , Steven Rostedt , Sergey Senozhatsky , Rasmus Villemoes Subject: Re: [PATCH v3 3/3] vsprintf: Move space out of string literals in fourcc_string() Message-ID: References: <20220126141917.75399-1-andriy.shevchenko@linux.intel.com> <20220126141917.75399-3-andriy.shevchenko@linux.intel.com> <202201261321.34794CCF3@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202201261321.34794CCF3@keescook> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kees, On Wed, Jan 26, 2022 at 01:22:32PM -0800, Kees Cook wrote: > On Wed, Jan 26, 2022 at 04:19:17PM +0200, Andy Shevchenko wrote: > > The literals "big-endian" and "little-endian" may be potentially > > occurred in other places. Dropping space allows linker to > > "compress" them by using only a single copy. > > > > Rasmus suggested, while at it, replacing strcpy() + strlen() by > > p = stpcpy(), which is done here as well. > > > > Signed-off-by: Andy Shevchenko > > Acked-by: Sakari Ailus > > --- > > v3: no changes > > lib/vsprintf.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > > index 4e8f3e9acb99..e2a1d89f1a5c 100644 > > --- a/lib/vsprintf.c > > +++ b/lib/vsprintf.c > > @@ -1781,8 +1781,8 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc, > > *p++ = isascii(c) && isprint(c) ? c : '.'; > > } > > > > - strcpy(p, orig & BIT(31) ? " big-endian" : " little-endian"); > > - p += strlen(p); > > + *p++ = ' '; > > + p = stpcpy(p, orig & BIT(31) ? "big-endian" : "little-endian"); > > > > *p++ = ' '; > > *p++ = '('; > > No need for any of the manual construction nor stpcpy(): > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index d7ad44f2c8f5..aef8bd2789a9 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -1788,14 +1788,9 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc, > *p++ = isascii(c) && isprint(c) ? c : '.'; > } > > - strcpy(p, *fourcc & BIT(31) ? " big-endian" : " little-endian"); > - p += strlen(p); > - > - *p++ = ' '; > - *p++ = '('; > - p = special_hex_number(p, output + sizeof(output) - 2, *fourcc, sizeof(u32)); > - *p++ = ')'; > - *p = '\0'; > + snprintf(p, sizeof(output) - sizeof(*fourcc), " %s (0x%x)", > + *fourcc & BIT(31) ? "big-endian" : " little-endian", > + *fourcc); > > return string(buf, end, output, spec); > } > > > (untested) This could work but results in two nested calls to vsnprintf(). I'd definitely avoid that, due to stack usage and then albeit it's easy to see the recursion will end with two iterations, that will very fast cease to be the case if you keep applying the pattern. -- Regards, Sakari Ailus