From patchwork Tue Nov 15 00:47:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: guo.ziliang@zte.com.cn X-Patchwork-Id: 20109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2445517wru; Mon, 14 Nov 2022 16:49:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4kEMsyUHtC7Beio8d2VZquNpRlww0/0XFyan7kiBe0dJL14JgqEau4D4utMMdga1/wqvmA X-Received: by 2002:a17:906:154f:b0:78d:9bcf:4d9f with SMTP id c15-20020a170906154f00b0078d9bcf4d9fmr11914997ejd.749.1668473379044; Mon, 14 Nov 2022 16:49:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668473379; cv=none; d=google.com; s=arc-20160816; b=Lha1bZ6v3RtMrKWut3BQPYlnLPz5Br8zQS+9bTuW2sM1/l5gl7VANHEQ+cSUut9Nc4 nlkoaZ02zwFjHieUB8paWYG3PNaRahulqOcw0i65Ik/ec6CFk+oVUTVoZRdqbz7tQgSj EACbyA0havGn6XDa+ebSvmfNba0s9r3PIHuPchxclfbGgFmAxVT2Ih+GFr3dAg+YWuc3 R3J57LgJtX8iGnx8fq/8bXUi6zWDQqPX6YykXo4UxLrqRz6BExz+ylyBGTjisxXKz2/r jLRIHOt7xO+J8gK/a0NP0br6phzyCppF62muNCa7UWZZpdlySHnxUOgOBvMrOonVrY7N w71Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=eayDN3srp+aWLmfabOuU8Bkm78K8J7xnOE+FuHHgvN4=; b=zQKs0PKoiDqcvcvOYDw4Ta+c0jNHgf9HXTGR4WO7IQjPGumZxVNSMZEHEyENivCr0N BiSoZw2qwHexC4F/6qZ2zgo+0Td7UtZSrizrdQk6vaz5pGDjDDbqo3IgXLzIY3p18xXm uAvV5YELhYxCiRBTp1dzZWaWd9pGP3xlAPwTv6DPcflUKobT1RAgn6a2pHwokUOeSNfa Ulltzbsjdcn5t4ALkBHGo6KfKMlPvjU1r5zKhsumg+SuLPxEc4N4VLpAxVNT4gLIUuXa cfzTOaqxV/ma/jRnGRXOEFw8eaBXdOVOwuLtmLBG9CNyLQ7ITNVOmV6vT6eDnScyLhxl mZcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds5-20020a170907724500b0078d4962a32asi11214288ejc.961.2022.11.14.16.49.14; Mon, 14 Nov 2022 16:49:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236156AbiKOAsY (ORCPT + 99 others); Mon, 14 Nov 2022 19:48:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231969AbiKOAsN (ORCPT ); Mon, 14 Nov 2022 19:48:13 -0500 Received: from mxct.zte.com.cn (mxct.zte.com.cn [58.251.27.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A24511DA50 for ; Mon, 14 Nov 2022 16:48:11 -0800 (PST) Received: from mxde.zte.com.cn (unknown [10.35.20.121]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4NB6wn3BqszvLN for ; Tue, 15 Nov 2022 08:48:09 +0800 (CST) Received: from mxus.zte.com.cn (unknown [10.207.168.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mxde.zte.com.cn (FangMail) with ESMTPS id 4NB6wW2Gfzz9vSnx for ; Tue, 15 Nov 2022 08:47:55 +0800 (CST) Received: from mxhk.zte.com.cn (unknown [192.168.250.137]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mxus.zte.com.cn (FangMail) with ESMTPS id 4NB6wR6tl0z9tyD7 for ; Tue, 15 Nov 2022 08:47:51 +0800 (CST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NB6wN4bBmz8QrkZ; Tue, 15 Nov 2022 08:47:48 +0800 (CST) Received: from xaxapp01.zte.com.cn ([10.88.40.50]) by mse-fl1.zte.com.cn with SMTP id 2AF0liFD064621; Tue, 15 Nov 2022 08:47:44 +0800 (+08) (envelope-from guo.ziliang@zte.com.cn) Received: from mapi (xaxapp03[null]) by mapi (Zmail) with MAPI id mid32; Tue, 15 Nov 2022 08:47:45 +0800 (CST) Date: Tue, 15 Nov 2022 08:47:45 +0800 (CST) X-Zmail-TransId: 2afb6372e1b1ffffffffe7dbc722 X-Mailer: Zmail v1.0 Message-ID: <202211150847452601249@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , Subject: =?utf-8?q?=5BPATCH_linux-next=5D_kernfs=3A_use_strscpy=28=29_is_mor?= =?utf-8?q?e_robust_and_safer?= X-MAIL: mse-fl1.zte.com.cn 2AF0liFD064621 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.251.14.novalocal with ID 6372E1C8.000 by FangMail milter! X-FangMail-Envelope: 1668473289/4NB6wn3BqszvLN/6372E1C8.000/10.35.20.121/[10.35.20.121]/mxde.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6372E1C8.000/4NB6wn3BqszvLN X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749521142168421979?= X-GMAIL-MSGID: =?utf-8?q?1749521142168421979?= From: guo ziliang The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings. Signed-off-by: guo ziliang --- fs/kernfs/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 1.8.3.1 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 77d7a3a..fbb8df4 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -844,7 +844,7 @@ static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent, spin_lock_irq(&kernfs_pr_cont_lock); - len = strlcpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf)); + len = strscpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf)); if (len >= sizeof(kernfs_pr_cont_buf)) { spin_unlock_irq(&kernfs_pr_cont_lock);