Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3591261pxb; Mon, 30 Aug 2021 06:09:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwViZxG1nnz2RY7hyA3MRv/COKHdC8IXFmDGlxuGi38EHCpHpTspRbD1Hzy0F1mwhTCAi4k X-Received: by 2002:a6b:b512:: with SMTP id e18mr18736199iof.98.1630328969272; Mon, 30 Aug 2021 06:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630328969; cv=none; d=google.com; s=arc-20160816; b=Y6AQD+2/OtaOWfhCmXtXbzXifgjBWbmxI/m4xTFesYNUXBIDENEMPT609Kn7EyASro Ph4p4q/rfscei/xDuDruVD0B+JWhtUMgTSfLhhNroZGqBx4YB8KOWPVqh/8iuTBCtw9i qpnd7y/9nY4jhj+nBwO7cPnyeQDLoalVNvxo84rFfGkt9xsvMQ6y6g90gE0xcT4i0Qge Zmi9JMMOaRKN2Qg2DWC7NGuNdkslyIL+wihYf5pC2KPCCoeepcHc8c1cSytluwYYVjXD hu2ApD3UyDerkIG8SjP5DUxfaz5tdgfc0CdrSPMT29RsqfWTPhJWHWpbWf17eJbFxhdf U5KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=WRpsyl8+WmrN/Ber8ZPVPbhMhMPQQGqzIW41/4tIMVM=; b=ZpUqwICKBdH4tfr0Y0whFlOtffwh4wJEDoDJSRTxT+1t2XR3Kw3GV5J9adnTMTvyOX +JH0GiLRPOISM8EagtC6xfM5JvzSY6+z6WXL1pNWZH4Xof7v5wMFdswMpz6xXe4owumZ s7USZ+8PeAz59KsVLxlGgyCa5YyBFrGsHc9nakrZ3QamrzhjjqByq87n7zU0Lt8qz/3R HumL3yWOiGQsQ1uafqWk16HK/8dW7/zmMsWL93aENtcx5szdxo6rZigxFgjWCgqRHXTf ZO8GvT/iUrsY8/gGCZDssuXvVy19VUGuJql1C6WDetOHXcL5BiYSlHSjwJ5NBgb7JF5N TmiA== ARC-Authentication-Results: i=1; mx.google.com; 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 m9si15054600iow.85.2021.08.30.06.09.12; Mon, 30 Aug 2021 06:09:29 -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; 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 S236729AbhH3NHN (ORCPT + 99 others); Mon, 30 Aug 2021 09:07:13 -0400 Received: from smtpbg126.qq.com ([106.55.201.22]:32742 "EHLO smtpbg587.qq.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229446AbhH3NHN (ORCPT ); Mon, 30 Aug 2021 09:07:13 -0400 X-QQ-mid: bizesmtp34t1630328753t2e56dzr Received: from localhost.localdomain (unknown [171.223.99.71]) by esmtp6.qq.com (ESMTP) with id ; Mon, 30 Aug 2021 21:05:52 +0800 (CST) X-QQ-SSF: 01000000004000C0D000B00A0000000 X-QQ-FEAT: tc6S58rF1JAWTi8uE0WstgfmSWYoacx5MpqcEQL0gJM+EEXKxm6nBJGii/fwI 1EIuEkDyURX6Q68j/etgS4RvKD9IL0aYVD8o3BQ3306+Hr6fcRJqCUCh+DO0ykISoP9Ybfc UdiU/LXUW/HaIPHgn7w5Du83MaxbyGgE2ZZD2k6zFFR59YRyOnjcmatbb2T/NN80rPh5GBA zzQuQgW6F3MDolm685WQuhKSOdnNnlB3IBl2GdLrTX2gv7TLe3I/z+/GSFp3zLQxG+ae96u wvtrG1lc5JWzudryxvVJHDXfTPo8gTv6IylLmWY7eK4uqdM8Lwkl94M5Hc7Ois7rpwzpWFh LfrXDtd3PAjjsQlY00CZ8Q/gNK9dw== X-QQ-GoodBg: 0 From: Jason Wang To: davem@davemloft.net Cc: ioana.ciornei@nxp.com, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Wang Subject: [PATCH] dpaa2-eth: Replace strlcpy with strscpy Date: Mon, 30 Aug 2021 21:05:31 +0800 Message-Id: <20210830130531.12429-1-wangborong@cdjrlc.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:cdjrlc.com:qybgspam:qybgspam2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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/freescale/dpaa2/dpaa2-ethtool.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c index ad5e374eeccf..2da5f881f630 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c @@ -72,12 +72,12 @@ static void dpaa2_eth_get_drvinfo(struct net_device *net_dev, { struct dpaa2_eth_priv *priv = netdev_priv(net_dev); - strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); + strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%u.%u", priv->dpni_ver_major, priv->dpni_ver_minor); - strlcpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent), + strscpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent), sizeof(drvinfo->bus_info)); } @@ -191,11 +191,11 @@ static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset, switch (stringset) { case ETH_SS_STATS: for (i = 0; i < DPAA2_ETH_NUM_STATS; i++) { - strlcpy(p, dpaa2_ethtool_stats[i], ETH_GSTRING_LEN); + strscpy(p, dpaa2_ethtool_stats[i], ETH_GSTRING_LEN); p += ETH_GSTRING_LEN; } for (i = 0; i < DPAA2_ETH_NUM_EXTRA_STATS; i++) { - strlcpy(p, dpaa2_ethtool_extras[i], ETH_GSTRING_LEN); + strscpy(p, dpaa2_ethtool_extras[i], ETH_GSTRING_LEN); p += ETH_GSTRING_LEN; } if (dpaa2_eth_has_mac(priv)) -- 2.33.0