Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp471882pxx; Mon, 26 Oct 2020 12:44:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwS/tp83Qg4Sc5ZZI3Z7SevE7CW5BsZBPKJiSUXpHyDMhFdzHXNo0m5lAUjbKH8BFXPXr65 X-Received: by 2002:a17:906:af75:: with SMTP id os21mr16901337ejb.28.1603741484087; Mon, 26 Oct 2020 12:44:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603741484; cv=none; d=google.com; s=arc-20160816; b=zccF5hZZvEAUv76tiGaQ3lOM0PZ47/LTEesNTgI5flKK/9ak/qI5V2vDMUkqweV+6X 3svxBaGu3W3rVcXjzqU8WULzD5mQGsSaFiei9hIaDovdSWOYuJh/vMfx7d2pxbHvntBH 3jEGhLDl3pzDiQOfCH+6R6U2U6r3plk7P9yrJRvuT/F0yCwb0rb507IxJI2AebHgf/Up pxxAbrlInHIVMZFwQHzyoviHU31QzXFYgYFjkTdLCjFOpyq8/u9Z3w4NPbF2Zb06E99+ ljYJuUphTS1iESLzDCNBxETUNurpAWz4WIp0Z4Z/xE1qnTerPaQ0cx3i3x1a1tfGfAXw 438g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QkSxinCWqmI+cVcVClYJ/GEAkI05y2Uwx+JatGD/fUE=; b=x6vXU3SlH5b4JIkQRIRFs/+VRTCzkj5PqL4HoqsVp9GXUoBSri9wg5URtqK4rZ4ffd fDpKJlIjCTtfS0wOTyISDlC2mT2YXS4F7YlCZBVqtKHe/cvCx/bBf+BnqZ3rY/czvODZ 8aZmjGy/yjceohzCkXp+h/5/f6b4SdP36OFeni2/avnnsJSUTIQdv7g+Hw3VI947yqIu HGrgmOBT1eyb118ex663eL+KFz+a6YoFbLnqjJdZB3IqjNOOzeQU+oZ5I4BqTCxjdBuS k99lDs1HbVHs4MCAVwmW8umHF3wEZx7PU6Ame1VOLOuWIzPZpieOAtcTgQE3n+WVGpjL 056w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vSEVqhGM; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 20si7989135ejw.320.2020.10.26.12.44.15; Mon, 26 Oct 2020 12:44:44 -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=@kernel.org header.s=default header.b=vSEVqhGM; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1786495AbgJZQuU (ORCPT + 99 others); Mon, 26 Oct 2020 12:50:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:43482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1786321AbgJZQtq (ORCPT ); Mon, 26 Oct 2020 12:49:46 -0400 Received: from localhost.localdomain (unknown [192.30.34.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E9252221FC; Mon, 26 Oct 2020 16:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603730986; bh=RL766Tz5kKTS6+hZ5d7QbkmR7LmzywMZ451dW3cIvns=; h=From:To:Cc:Subject:Date:From; b=vSEVqhGMLk9CuisEXVYM5AMsksW+yyUTVJaIRWlLoqsmbj7fNlGB67V493rakD6Y3 klRjCNWhOrQfyLKikCgCnA7+X8VLJZC+e2KCEYjM+M3aJiF5XgXUrNBqfHS9dwOoo5 ckDFiDiOt9RM+xpMes9rzLYO+/7G0fi2D4xlFvjA= From: Arnd Bergmann To: Thierry Reding , Jonathan Hunter Cc: Arvind Sankar , Arnd Bergmann , Thierry Reding , Timo Alho , linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] firmware: tegra: fix strncpy()/strncat() confusion Date: Mon, 26 Oct 2020 17:49:21 +0100 Message-Id: <20201026164937.3722420-1-arnd@kernel.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v2: Use the correct arguments for snprintf(), as pointed out by Arvind Sankar --- 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..440d99c63638 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(pathbuf, pathlen, "%s%s/", ppath, name); 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