From patchwork Mon Sep 6 13:56:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 12477057 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D11E7C433F5 for ; Mon, 6 Sep 2021 13:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B127960200 for ; Mon, 6 Sep 2021 13:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242826AbhIFN6U (ORCPT ); Mon, 6 Sep 2021 09:58:20 -0400 Received: from smtpbg587.qq.com ([113.96.223.105]:33663 "EHLO smtpbg587.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232432AbhIFN6T (ORCPT ); Mon, 6 Sep 2021 09:58:19 -0400 X-QQ-mid: bizesmtp46t1630936616tmdbv0zp Received: from localhost.localdomain (unknown [171.223.98.107]) by esmtp6.qq.com (ESMTP) with id ; Mon, 06 Sep 2021 21:56:55 +0800 (CST) X-QQ-SSF: 01000000004000C0D000B00A0000000 X-QQ-FEAT: XNS/ZC4vffVNTZkm0uumHZ4/n+M4rXDPjCyZ8nrcw4j6Bxk6m+1S5KOBzrKfH cJhrGyTYPiscoVi1Uz0mxlqM9rKHDqETyOUhq0UkWfgXFTJSiEnoe7okpUBooYlgq5uSG1c efMlZXCqF71t1qMad3H2iXvqxVdsrdPqKjRiWe+HDuEktC0T48P6V8JtK1GcZpfnh7lbk22 JwHM58u0HZHr2IkDzVuIGri1/4QV7/DTnhrOyN0srAFrzecY4tfLoNZIAClR+Wc6tPV5Ix1 TCzHxF/YGdK2o6e3h8m6gG2i3UC+YLJEV1bCvotM8JcE6fPKoVA5pQLx6ORNHJ+nexzyDTY 6skN9UNOZ0vAmlo8Laqfu/yOgfAgA== X-QQ-GoodBg: 0 From: Jason Wang To: davem@davemloft.net Cc: timur@kernel.org, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Wang Subject: [PATCH] net: qcom/emac: Replace strlcpy with strscpy Date: Mon, 6 Sep 2021 21:56:53 +0800 Message-Id: <20210906135653.109449-1-wangborong@cdjrlc.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:cdjrlc.com:qybgspam:qybgspam3 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The strlcpy should not be used because it doesn't limit the source length. As linus says, it's a completely useless function if you can't implicitly trust the source string - but that is almost always why people think they should use it! All in all the BSD function will lead some potential bugs. But the strscpy doesn't require reading memory from the src string beyond the specified "count" bytes, and since the return value is easier to error-check than strlcpy()'s. In addition, the implementation is robust to the string changing out from underneath it, unlike the current strlcpy() implementation. Thus, We prefer using strscpy instead of strlcpy. Signed-off-by: Jason Wang --- drivers/net/ethernet/qualcomm/emac/emac-ethtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/qualcomm/emac/emac-ethtool.c b/drivers/net/ethernet/qualcomm/emac/emac-ethtool.c index 79e50079ed03..f72e13b83869 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac-ethtool.c +++ b/drivers/net/ethernet/qualcomm/emac/emac-ethtool.c @@ -100,7 +100,7 @@ static void emac_get_strings(struct net_device *netdev, u32 stringset, u8 *data) case ETH_SS_STATS: for (i = 0; i < EMAC_STATS_LEN; i++) { - strlcpy(data, emac_ethtool_stat_strings[i], + strscpy(data, emac_ethtool_stat_strings[i], ETH_GSTRING_LEN); data += ETH_GSTRING_LEN; }