Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2859563pxb; Mon, 6 Sep 2021 07:00:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf9eWqzVu4lYGj0lYSfCmvQd/IlA3/TFPywwRZbMj2AlS+3C4C/v/dJ1RN/SyOn5aNCCKM X-Received: by 2002:a05:6e02:1094:: with SMTP id r20mr8294425ilj.55.1630936826668; Mon, 06 Sep 2021 07:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630936826; cv=none; d=google.com; s=arc-20160816; b=kj3i4sDDwLzpstJg6Pdm1MWpXRTnO3hbApMpWse7HW8RW2K8v1T3h9pN7qofmg8smO zbqsuZBe+mli9i7PenmNjpckz92mLqzHInYOvpMV/aZjQjr1Np7ktdeXfm/dKVhaHbRY YHJ9lB1wHfia4/PeJ70NKm51AEW6ZU17fbjM5jpaUpQnU3XF+N6U6UtH28orQHtFONdt yzJqd/ddJ0uNwEMCvxWvnmf3oN/D4ENkGX91b59yXNoKBSfpbzRs3Pd/MADaTO4PCUG0 M68dkt2Dnvw9UQAWmqk6KPpzDllf3fCSofa1Jv7b+OfmxDqZFijUVKGPeoUyr7/v7ORd nDBQ== 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=F72AijPBs3lpOySfPo9jMhBVo6G4cUzzRTP455JWU/Q=; b=ges4CvqrhIBuBz3Dry1Ml5ME0BnCnMxFsEhyndid2aTVF5dTc/bCP6a0QP2HXQ1lKD glTvurO97HQYwkeEh6kbFfj+TOLLXaGx5v4X+fSn5tMeok2sch+nveTgIq0z6qtfOu91 dbKpPld7M9mgXhXfApoY/OFC72NO7q77l7YhmNjawycXIXeoaKGtH6hsr31r4NvzKbz5 GZJcorB+vIIQI0gyFoBV9beYbkoGd/v7N/b1NmuCP5CWdDX/yAwATpi8zoZ9b8BaObu+ SvHXeL8eVB7Tiszo4+VSH8r9+PM/KHbUOLG9RTGHuW2kmE7z2KLqH+Jtn66hnKAfUhqe R5zg== 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 q15si8900362jaj.16.2021.09.06.07.00.14; Mon, 06 Sep 2021 07:00:26 -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 S242760AbhIFN6U (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:cdjrlc.com:qybgspam:qybgspam3 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/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; } -- 2.33.0