From patchwork Mon Dec 20 08:19:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1570931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JHXYz0Vscz9sRN for ; Mon, 20 Dec 2021 19:19:35 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4JHXYy6q79z4xRC for ; Mon, 20 Dec 2021 19:19:34 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4JHXYy6Zc9z4xgt; Mon, 20 Dec 2021 19:19:34 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4JHXYy6WSQz4xRC for ; Mon, 20 Dec 2021 19:19:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234508AbhLTITd (ORCPT ); Mon, 20 Dec 2021 03:19:33 -0500 Received: from smtpbg127.qq.com ([109.244.180.96]:19826 "EHLO smtpbg.qq.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231147AbhLTITd (ORCPT ); Mon, 20 Dec 2021 03:19:33 -0500 X-QQ-mid: bizesmtp32t1639988363t3g0gigw Received: from localhost.localdomain (unknown [118.121.67.96]) by esmtp6.qq.com (ESMTP) with id ; Mon, 20 Dec 2021 16:19:21 +0800 (CST) X-QQ-SSF: 01000000002000D0K000B00A0000000 X-QQ-FEAT: ZHPL5yNEtlkMlEtAlTXCD7MKTuPb3NRc04hFy/80o+vxDMQpLJApBCyyEtGCm FoYMjhUBkLP6D7MS9EdNS2JJ1d7Sp3Or/8YIQad+VCh+mFtvRf8Z6c7/0Nh8+7xjjE67AFr vBSy9Sb7Qt0Dgnaeafsq36uLbPFSCnnmrH8aVSGtNbwVuKCXfs0fdHjrNN89/empO1f45wT +ziL6crExfexa/K+5DBucDOGYzYoyoGqrMYuWsatWkdq2vdabbzHu/Ip0bKjOT/S8jVxQvG pkEOTGY13DPHXbcETULKFipVRZiYG85qYTIrgsrSEQz3l3F4RHVh2imfAz58jwFJFZ4pEhJ Yhp5g9Vj2jCE3t4Py+iYkzgfIT9oQryVin1elCQg5L6M2EBsKo= X-QQ-GoodBg: 0 From: Jason Wang To: davem@davemloft.net Cc: viro@zeniv.linux.org.uk, wangborong@cdjrlc.com, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] sparc32: use strscpy to copy strings Date: Mon, 20 Dec 2021 16:19:17 +0800 Message-Id: <20211220081917.922068-1-wangborong@cdjrlc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:cdjrlc.com:qybgspam:qybgspam1 Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org The strlcpy should not be used because it doesn't limit the source length. So that it 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, replace strlcpy with strscpy. Signed-off-by: Jason Wang --- arch/sparc/kernel/setup_32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/sparc/kernel/setup_32.c b/arch/sparc/kernel/setup_32.c index c8e0dd99f370..c3fd44b7fd1a 100644 --- a/arch/sparc/kernel/setup_32.c +++ b/arch/sparc/kernel/setup_32.c @@ -120,7 +120,7 @@ static struct console prom_early_console = { .index = -1, }; -/* +/* * Process kernel command line switches that are specific to the * SPARC or that require special low-level processing. */ @@ -302,7 +302,7 @@ void __init setup_arch(char **cmdline_p) /* Initialize PROM console and command line. */ *cmdline_p = prom_getbootargs(); - strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE); + strscpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE); parse_early_param(); boot_flags_init(*cmdline_p);