Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5637943pxb; Wed, 26 Jan 2022 17:14:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJywbgR9DRtQ+WYmY97874AhpoKYSYQGwxpO8hbadCCqCB8Hi2841g41/ZLHukm6BXaapGRM X-Received: by 2002:a63:924c:: with SMTP id s12mr1064144pgn.257.1643246044279; Wed, 26 Jan 2022 17:14:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643246044; cv=none; d=google.com; s=arc-20160816; b=NQB4tQdA90jgZivpnWMvOrBnJ9rdcYmOBVYlK5A1zAO57ZSGCdCPUM4U2YG/klwwuv a8u4RnasBDnlS1a8OODq84/l8UbIwMrY9CBK7Gp7D0dpGRB/23aIszyEo2ObwjnQnOkB CSUJE/j/xZFkvwfekbpiy75Kzq9dkvHgDAGukuLKqNx2KIjhbJA7ocQXqbpiTHQcAnlS 97VTC884GoJNUATV/Lbta/A8xqnwvL++3jva3c5oX0p9ZkR8GoLVg0RhKWPdRC2u++jC M0QrrBp9BgoOBJhecvwheWTzNhM9feN6YZ6UzewRtqUwRDrZgES/fXHR5oFLd2al33ky 5G+A== 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=WwF77iiskBi0tVOR9grcbM66YdixrtGONmO8eGaXJuM=; b=LvVbgO/69S8iwG7xPwapILojdIZ9Eu6jFR9HfvHZ15UXh1Yi6VX7Z2HxV4miFZ/snh lxeWaMJLf2Upyj18ch2kY5ouWLxfRrN0ZsJ04Qj3UxIa+F/j5VljkNNRCe1CyOq0B30Y RrxWN24Lc3cQM9tuk666HfA2FAC0XPw3SFLsGRIXMszW/Jix2AIaN419nPnbr0BAwjm5 lKpbxWV8ZoSjVIb6kl8CXvzBD7cFNPqYOGqMQK5ygXNIQAJMpuM3L0hVcfchdr83XExm 7FOa3qKStSQxPL4OQvgdTcuOlMUBPhXcUNlB34eeG3nIKKlX2lUfO/7YHmPVsFvJRylo VJFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V1i1qj1o; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p34si762829pgb.807.2022.01.26.17.13.52; Wed, 26 Jan 2022 17:14:04 -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=@chromium.org header.s=google header.b=V1i1qj1o; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231942AbiAZVWf (ORCPT + 99 others); Wed, 26 Jan 2022 16:22:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbiAZVWe (ORCPT ); Wed, 26 Jan 2022 16:22:34 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B2E2C06161C for ; Wed, 26 Jan 2022 13:22:34 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id o11so864011pjf.0 for ; Wed, 26 Jan 2022 13:22:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=WwF77iiskBi0tVOR9grcbM66YdixrtGONmO8eGaXJuM=; b=V1i1qj1oiJh62NhKr9M7Fyd5gODgYFX4zN1hQPxtYWlMzEXVMC85/I1+X2NgQD+LRC 0me7e11svC4wFCcWBEAGe3akZh8FmFEanhKJw44KLS3bM7/fvz2gn5TF9DpiHIZhEzCQ NUd6Y9ikCnkixs3SjmCCVGnumh3odJE8CIpVE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WwF77iiskBi0tVOR9grcbM66YdixrtGONmO8eGaXJuM=; b=kejsOK/J2OkLcnJX3a1hAKHYVgYEcJtRS6hvg2M0ArdZDRvWpR6MUocpuuL9VqroQ8 HsXhzQotRuAOI6L7ydyvz4j4L+qFNkCDHqf5zbFRb80RqeWolnmqa0vHoeImNSx7DyoK FaSbLOii8pRWxS8qPBReJWcrGIy39lJkR2nt2xRUUPnHH9FuKSLevLEhsBIv6mTgrQZm i3CO/O8Avob1j16XPDexnfT3qaodV2WC88GMSCJxW8Td/ZeF8N129rPx0f7WBnoCDgY2 A3/0INX/5EsQZungwZRyOB/QFLpFTX4csLa1sd7cUy9YvVeqr5eCk34JaIZB9z4o+H57 JIiA== X-Gm-Message-State: AOAM531r6Esjs78qzCVWqfKr/Co5PzvvigjpPw2Ut/SjS98s7qjMRu8V 1+wyUGZ8Vwj0/V6k63vEMOtQ4A== X-Received: by 2002:a17:902:ce8f:: with SMTP id f15mr518312plg.3.1643232153633; Wed, 26 Jan 2022 13:22:33 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y13sm3009620pfi.2.2022.01.26.13.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 13:22:33 -0800 (PST) Date: Wed, 26 Jan 2022 13:22:32 -0800 From: Kees Cook To: Andy Shevchenko Cc: Francis Laniel , Petr Mladek , linux-kernel@vger.kernel.org, Andy Shevchenko , Steven Rostedt , Sergey Senozhatsky , Rasmus Villemoes , Sakari Ailus Subject: Re: [PATCH v3 3/3] vsprintf: Move space out of string literals in fourcc_string() Message-ID: <202201261321.34794CCF3@keescook> References: <20220126141917.75399-1-andriy.shevchenko@linux.intel.com> <20220126141917.75399-3-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220126141917.75399-3-andriy.shevchenko@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- Kees Cook