Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1097467pxt; Sat, 7 Aug 2021 00:26:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2grEUhphlQBOrNnJXLwIFLVailsJ/f6x4W0ogVqJXq9OzxHMmLyxwoEcrtxBd2Nb0qeV/ X-Received: by 2002:a05:6e02:e0c:: with SMTP id a12mr43289ilk.179.1628321172018; Sat, 07 Aug 2021 00:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628321172; cv=none; d=google.com; s=arc-20160816; b=oG2nTfIGpNzkXawkhEREoJmkB5TmOn1RhBKiM6vxPgLQ+oBdK+F2Om5F4hJOC76hcm DpwfTRXie95NfW6TTbSdxcyscPc/UIDTF7EjRS8xzO0illP7eYLeITAi1GE9bW3ClIvF ObCV3wpevHxpq6SAxpS8UGcJ8tZ4N03Xqv1sX8xE0mu6v+HRA2+6T2/FgVKziQQqOnN/ HVOB5tn+g1aqX5CIE8eczy7WoQysxZdrS/VRsRKog2WwFZHNz2Hpy35llLAsmBdi/K5k HPPSitBrDTzzwlXft3e+3xP3liWqmUkir96DoLpn7o4cus3Xib31dGXTw9oT7zDyKzIV caiQ== 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=Cn43wAs5Am6LnRikvOeYa2IcI88/gNNdzfOHfuxqTVI=; b=SilO/QCe6Z1hBW5ubQZ1vewWohOE9F3K/rnWt+sY7XOsqYRUo0hbheLxIxESpXzusr jJrIWaWjly/KZW0+F5c0aOriBjbsjg7Ngeu+ZEHvA0UyEgQ7RUkedynZiUv6kBW0N64C mWFY78z+7FcKTdWmyqLOFkT/kZL7LTyF4zroLM1vC0ruKLbFZqecBHpOI182YRBPTaeO 7NmxW457vd6MOs20Wsf/fF57Mh7rkrxGt29SIgv7wv2EL64B+O2uhk0T/VkvzWpFheFE XGSs7PeXRroyjjkuyUtySqIVZ4KHPSTXE0O1w1VQOkmTz6q+sM1AoElbTn5/YOwkdMmM GXDg== 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 p76si2067758iod.9.2021.08.07.00.26.00; Sat, 07 Aug 2021 00:26:12 -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 S231490AbhHGHZd (ORCPT + 99 others); Sat, 7 Aug 2021 03:25:33 -0400 Received: from smtpbg511.qq.com ([203.205.250.109]:43487 "EHLO smtpbg511.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231375AbhHGHZc (ORCPT ); Sat, 7 Aug 2021 03:25:32 -0400 X-Greylist: delayed 610 seconds by postgrey-1.27 at vger.kernel.org; Sat, 07 Aug 2021 03:25:31 EDT X-QQ-mid: bizesmtp33t1628321103t79kuz7l Received: from localhost.localdomain (unknown [125.69.42.194]) by esmtp6.qq.com (ESMTP) with id ; Sat, 07 Aug 2021 15:25:02 +0800 (CST) X-QQ-SSF: 01000000002000B0C000B00A0000000 X-QQ-FEAT: FsG0r2mBeluv3Zd9YWfYoh+AeeQRy3mwRvhGF/vi0SQ8PvrFHvtPsenqipt2u nQYQ+mvnRsp2/+RsuU7KsxD8TtXzL8kT+dqidTfLRsmt1rX95RGtB+NEiGUglWXK9n16Rhu OQfdZE/gWhHz9bJ0HRmy6nxoeU4+bBKiHmoeuezT9zzJNtmJx8SI/3KUmWu9nDhnMR0z9EF 0i6USB7MTzzX9TapcAP9dqZCCpK0vxbCruZzhEFH8Hugwj1E9hC2ikRbcKarFxppoAj92ec KKyjCMDeIRV7pdT7FwboFQUHLzJXP29NxEsPvbZ7dFJBMbvhgUm+gdfljv55DCegSwVd7gl 8/LEMVK X-QQ-GoodBg: 0 From: Jason Wang To: ley.foon.tan@intel.com Cc: akpm@linux-foundation.org, wangkefeng.wang@huawei.com, wangborong@cdjrlc.com, andreas.oetken@siemens.com, linux-kernel@vger.kernel.org Subject: [PATCH] nios2: use strscpy to replace strlcpy Date: Sat, 7 Aug 2021 15:24:31 +0800 Message-Id: <20210807072431.66478-1-wangborong@cdjrlc.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:cdjrlc.com:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 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 --- arch/nios2/kernel/setup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c index cf8d687a2644..02fe70b6d78e 100644 --- a/arch/nios2/kernel/setup.c +++ b/arch/nios2/kernel/setup.c @@ -121,7 +121,7 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6, dtb_passed = r6; if (r7) - strlcpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE); + strscpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE); } #endif @@ -129,10 +129,10 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6, #ifndef CONFIG_CMDLINE_FORCE if (cmdline_passed[0]) - strlcpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE); + strscpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE); #ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB else - strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); + strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); #endif #endif -- 2.32.0