Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp535876pxx; Mon, 26 Oct 2020 14:34:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoehTtFYxZ6rE/uaBdF0MOLFjAiHN/cQiNroV+vk+aumdOGtRTvdfTnZiwqpGvTLXPhiZ3 X-Received: by 2002:aa7:cd42:: with SMTP id v2mr17318623edw.151.1603748049884; Mon, 26 Oct 2020 14:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603748049; cv=none; d=google.com; s=arc-20160816; b=BtCfjAatpHX4PdG850DB4Y5/VmmL5nk6BmycSVP1j4FaTTzwK7EOuVTalf3qPMdcgu faOpu2undRXZYDYs1HJLrJc2Ad1UANcUVh+fBSRpDu216Fef26jY58bqGk3z7mAzzSik w7dkqX1kcOu+me58iPhBmZIQwhxhJixiX5Y38xmWfYyIM8+foSwkFvEhbqtwDnRSj4cs 65UBOpvP9xpxM5RT8N3amOFwMRaFm7xRUobQRc8CIJg4jsnk24rB3AIy/QT86LjTQ/+X IJSRuJi1OEV+kT9ZMIkzTseYukiGJ1cCoh/T+YbBHQMf/I+vH5WgBjpurGwBgQPjmT4v oWOw== 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:date:from:sender:dkim-signature; bh=ERc0BB3m56dqHl5HJ2w8Pcruz+ZjG3J2VixGsoMlKiE=; b=eTU4GLdDFwD8k16Ymn+G9BA4p964j33BOPey9gnTWDS+yxuWfRnSxSy2O5y3wx1wrQ /wpLmXn0Ks4pdt4xm/GiaGwELQ0L0EIK6XiLQL3H/FI+oWMkoxlt8tdt+0TKlOByJ+FP PExlPhacYFOo5EYonXIdSk+lVQOmgK6ncgF603XuiSlMKJCLaCuCyuJuOoS2lScmGxHI 9PtxPhulW1qOsOnwG6DaYgm2TrxojBGN118X5Uy9NEVV8NoBx72/zafoAU0WLzXMIkr/ xUSozkha6uKGKZHn6wOEbjjqTc71bD3u2p/xPHIIL9JXeHxZYxgVls0wmDxUo14cVpiP PsyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=H59SXVYZ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd5si7972266edb.451.2020.10.26.14.33.47; Mon, 26 Oct 2020 14:34:09 -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=@gmail.com header.s=20161025 header.b=H59SXVYZ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1786127AbgJZQfc (ORCPT + 99 others); Mon, 26 Oct 2020 12:35:32 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:36033 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1786122AbgJZQfb (ORCPT ); Mon, 26 Oct 2020 12:35:31 -0400 Received: by mail-qt1-f196.google.com with SMTP id c5so7156619qtw.3; Mon, 26 Oct 2020 09:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ERc0BB3m56dqHl5HJ2w8Pcruz+ZjG3J2VixGsoMlKiE=; b=H59SXVYZzuvc8pz6mMLluvoPUBaQ+n6VGpDxxsXjRPth9mNlPH8qSJm+TxeBmyMVSn cJ8U6ATe5IeU/Jyv8UiZTzTqBgR1vkf57EGlrsVmnsTaVuk1U0GccRmhKfFmuTxSOS47 uuLbRBGhNTqY9yxLV39aLqpdVDT4hVOsJ9lDZktw6asztD1Wj10JvL3j8qfcJzlSrksR GEgIWW5k+RQUT1A1u65xRkj5gdNRlKB1Ugi3L3+D2FGdLH8s2rtfqWjXUGGAMj6TH/NM 3TXo6S5jO+IxdViq51ec2mG34STdSdD8qLwXmaZ/IU2DrjOTiPkXIEkX/N8UfaEYc6Lk YFXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=ERc0BB3m56dqHl5HJ2w8Pcruz+ZjG3J2VixGsoMlKiE=; b=XTQkzqQ704u+WuG6rSkX4R0Xx+uc+18ljegLwly0wgFMWH9oBz4ycv8ZkQyRQoRqDp QTjiw2mE4d/B7eQb+/Hv/rmtKQFg9YNhSa/ZrJfpD7aIIJu0L7DsLeAaBdAK5gVXuHDD DPnNuP63TCkIeQFHhJlyXdCMmgjd5BrrV6moDSBi4+IonTVHZP6kntCcGDcjixB67WnR GKJRKCa9IiqVRC2oI8p/WFt0z7nNspCAkUUinVWGYbjfytHJViE6t7FUQSgGxDZzZXFu xeJgoDsPPVz0OEUBngP/RxivhEJMI5HOnFsczcNe//iKrHQtsuN+/5l9QNpCF8KbXFbm a6+g== X-Gm-Message-State: AOAM530XDKdebSbAuf309jpLeJiDO1eC/Y4NEQ3paRs8jwYUda2Bc1hx gU/uQfrw0J17aenLQzkK+H8= X-Received: by 2002:ac8:5a10:: with SMTP id n16mr17525630qta.164.1603730127393; Mon, 26 Oct 2020 09:35:27 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id z66sm6815852qkb.50.2020.10.26.09.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 09:35:26 -0700 (PDT) Sender: Arvind Sankar From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Mon, 26 Oct 2020 12:35:24 -0400 To: Arnd Bergmann Cc: Thierry Reding , Jonathan Hunter , Arnd Bergmann , Thierry Reding , Timo Alho , linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] firmware: tegra: fix strncpy()/strncat() confusion Message-ID: <20201026163524.GA1491649@rani.riverdale.lan> References: <20201026161026.3707545-1-arnd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201026161026.3707545-1-arnd@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 26, 2020 at 05:10:19PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > The way that bpmp_populate_debugfs_inband() uses strncpy() > and strncat() makes no sense since the size argument for > the first is insufficient to contain the trailing '/' > and the second passes the length of the input rather than > the output, which triggers a warning: > > In function 'strncat', > inlined from 'bpmp_populate_debugfs_inband' at ../drivers/firmware/tegra/bpmp-debugfs.c:422:4: > include/linux/string.h:289:30: warning: '__builtin_strncat' specified bound depends on the length of the source argument [-Wstringop-overflow=] > 289 | #define __underlying_strncat __builtin_strncat > | ^ > include/linux/string.h:367:10: note: in expansion of macro '__underlying_strncat' > 367 | return __underlying_strncat(p, q, count); > | ^~~~~~~~~~~~~~~~~~~~ > drivers/firmware/tegra/bpmp-debugfs.c: In function 'bpmp_populate_debugfs_inband': > include/linux/string.h:288:29: note: length computed here > 288 | #define __underlying_strlen __builtin_strlen > | ^ > include/linux/string.h:321:10: note: in expansion of macro '__underlying_strlen' > 321 | return __underlying_strlen(p); > > Simplify this to use an snprintf() instead. > > Fixes: 5e37b9c137ee ("firmware: tegra: Add support for in-band debug") > Signed-off-by: Arnd Bergmann > --- > drivers/firmware/tegra/bpmp-debugfs.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c > index c1bbba9ee93a..9ec20ddc9a6b 100644 > --- a/drivers/firmware/tegra/bpmp-debugfs.c > +++ b/drivers/firmware/tegra/bpmp-debugfs.c > @@ -412,16 +412,12 @@ static int bpmp_populate_debugfs_inband(struct tegra_bpmp *bpmp, > goto out; > } > > - len = strlen(ppath) + strlen(name) + 1; > + len = snprintf("%s%s/", pathlen, ppath, name); Didn't you get any warnings with this? It should be len = snprintf(pathbuf, pathlen, "%s%s/", ppath, name); right? > if (len >= pathlen) { > err = -EINVAL; > goto out; > } > > - strncpy(pathbuf, ppath, pathlen); > - strncat(pathbuf, name, strlen(name)); > - strcat(pathbuf, "/"); > - > err = bpmp_populate_debugfs_inband(bpmp, dentry, > pathbuf); > if (err < 0) > -- > 2.27.0 >