From nobody Thu Sep 18 07:19:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A6C0C10F1E for ; Fri, 9 Dec 2022 07:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbiLIHpt (ORCPT ); Fri, 9 Dec 2022 02:45:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbiLIHpp (ORCPT ); Fri, 9 Dec 2022 02:45:45 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C789540900; Thu, 8 Dec 2022 23:45:44 -0800 (PST) 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 4NT33W18jGz8QrkZ; Fri, 9 Dec 2022 15:45:43 +0800 (CST) Received: from szxlzmapp02.zte.com.cn ([10.5.231.79]) by mse-fl1.zte.com.cn with SMTP id 2B97jScJ046261; Fri, 9 Dec 2022 15:45:28 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp04[null]) by mapi (Zmail) with MAPI id mid14; Fri, 9 Dec 2022 15:45:31 +0800 (CST) Date: Fri, 9 Dec 2022 15:45:31 +0800 (CST) X-Zmail-TransId: 2b066392e79b6cce31ed X-Mailer: Zmail v1.0 Message-ID: <202212091545310085328@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , , , , , , , , , Subject: =?UTF-8?B?W1BBVENIIGxpbnV4LW5leHQgdjNdIHg4Ni9wbGF0Zm9ybS91djogdXNlIHN0cnNjcHkgdG8gaW5zdGVhZCBvZiBzdHJuY3B5KCk=?= X-MAIL: mse-fl1.zte.com.cn 2B97jScJ046261 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 6392E7A7.000 by FangMail milter! X-FangMail-Envelope: 1670571943/4NT33W18jGz8QrkZ/6392E7A7.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6392E7A7.000/4NT33W18jGz8QrkZ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xu Panda The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings. Signed-off-by: Xu Panda Signed-off-by: Yang Yang --- change for v3 - remove the remaining definition of p, and fix the mistake which leads to eating one character. Thanks to Andy Shevchenko again. --- arch/x86/platform/uv/uv_nmi.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/platform/uv/uv_nmi.c b/arch/x86/platform/uv/uv_nmi.c index a60af0230e27..a55550b779e1 100644 --- a/arch/x86/platform/uv/uv_nmi.c +++ b/arch/x86/platform/uv/uv_nmi.c @@ -202,14 +202,10 @@ static int param_set_action(const char *val, const st= ruct kernel_param *kp) { int i; int n =3D ARRAY_SIZE(valid_acts); - char arg[ACTION_LEN], *p; + char arg[ACTION_LEN]; /* (remove possible '\n') */ - strncpy(arg, val, ACTION_LEN - 1); - arg[ACTION_LEN - 1] =3D '\0'; - p =3D strchr(arg, '\n'); - if (p) - *p =3D '\0'; + strscpy(arg, val, strnchrnul(val, ACTION_LEN - 1, '\n') - val + 1); for (i =3D 0; i < n; i++) if (!strcmp(arg, valid_acts[i].action)) --=20 2.15.2