Message ID | 202212031419324523731@zte.com.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1239818wrr; Fri, 2 Dec 2022 22:48:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf4r8iTLftRSwGl/2tqmKfX8hlRbZtRHxXjgflV73FUe3es49EtsL5zfrniYD55McVjug0kt X-Received: by 2002:a62:ea0e:0:b0:575:7bb:d6fc with SMTP id t14-20020a62ea0e000000b0057507bbd6fcmr32221927pfh.79.1670050109104; Fri, 02 Dec 2022 22:48:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670050109; cv=none; d=google.com; s=arc-20160816; b=xSn9IhA/FfuITGB50Y8DK2G9b/Gea9E2hjdhRZAHSCFCQ0FbnU2VMOwJ24ZY/onIkY J3LhJnMVUydW7QmoahMt34lQS+2EnYj7dVijmCZFbVveRjucgDi0R53z/Q/Aj85qmkTE M1K1tF7VpsLzLiWsLZgVORRtUOt6rAaTUIcB1fEV11TiaQw/kQ1vJXITVVWaltIVrMw6 M8rR8T677PrRYVdRU5H3+9D0AnD2MQ4uPpiyundwnB900aRD4ZH03x4l7rVw3a2DQ3GL tPG2GT1qtLIXgXmUkzkFp0qKRBKsLUg7pbZCKcFmpZgRsx8GxeYY8hq+/6M89FGCrqkO mnMw== 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=YBKFXnz1U7gbi30oeI8P+/z+tKvnPvPVgP3zyHzpzL0=; b=narV7eEj6x9Saxw8BYQOMFpMan7tRNJD92uXpZNwu6gzGX+ldbHXb4nELf23oQr/nO hWo/KaxqW9uw4RheZ+urgMVAZA7HM5hCVB4XDGY1kyDStFuG5sQxqeQ+uRUA33Xh503c HAX1RVaGq12JyZFer7B9P/dIJHAh7cuz0NewbdM2GHk8V5dHnwspEXlfOzL5SY7uqIxP IRhePNpmd0SlG9mfJQfXS3j7joyymQAFQyF+9lW1lcgsSCWcwr9U5FkM6SdZsQKpbSaz +u87bIOX+JikzIviVohUTEcrnw8RoSqN40bnwRyGlv8peFh+qv8f+MLU+JEowGfPwvrm /VHw== 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 pj2-20020a17090b4f4200b0021406fde039si9294950pjb.156.2022.12.02.22.48.16; Fri, 02 Dec 2022 22:48:29 -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 S231154AbiLCGTi (ORCPT <rfc822;lhua1029@gmail.com> + 99 others); Sat, 3 Dec 2022 01:19:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbiLCGTg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 3 Dec 2022 01:19:36 -0500 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0933ED208F; Fri, 2 Dec 2022 22:19:36 -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 mxct.zte.com.cn (FangMail) with ESMTPS id 4NPKQt47vdz4xq1w; Sat, 3 Dec 2022 14:19:34 +0800 (CST) Received: from szxlzmapp07.zte.com.cn ([10.5.230.251]) by mse-fl1.zte.com.cn with SMTP id 2B36JU32087812; Sat, 3 Dec 2022 14:19:30 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp02[null]) by mapi (Zmail) with MAPI id mid14; Sat, 3 Dec 2022 14:19:32 +0800 (CST) Date: Sat, 3 Dec 2022 14:19:32 +0800 (CST) X-Zmail-TransId: 2b04638aea74ffffffff810fbe95 X-Mailer: Zmail v1.0 Message-ID: <202212031419324523731@zte.com.cn> Mime-Version: 1.0 From: <yang.yang29@zte.com.cn> To: <tony.luck@intel.com> Cc: <bp@alien8.de>, <tglx@linutronix.de>, <mingo@redhat.com>, <dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>, <linux-edac@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <xu.panda@zte.com.cn>, <yang.yang29@zte.com.cn> Subject: =?utf-8?q?=5BPATCH_linux-next=5D_x86/mce/dev-mcelog=3A_use_strscpy?= =?utf-8?q?=28=29_to_instead_of_strncpy=28=29?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl1.zte.com.cn 2B36JU32087812 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.251.13.novalocal with ID 638AEA76.000 by FangMail milter! X-FangMail-Envelope: 1670048374/4NPKQt47vdz4xq1w/638AEA76.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/<yang.yang29@zte.com.cn> X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 638AEA76.000/4NPKQt47vdz4xq1w 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751174463182656863?= X-GMAIL-MSGID: =?utf-8?q?1751174463182656863?= |
Series |
[linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
|
|
Commit Message
Yang Yang
Dec. 3, 2022, 6:19 a.m. UTC
From: Xu Panda <xu.panda@zte.com.cn> 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 <xu.panda@zte.com.cn> Signed-off-by: Yang Yang <yang.yang29@zte.com> --- arch/x86/kernel/cpu/mce/dev-mcelog.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Comments
> From: Xu Panda <xu.panda@zte.com.cn> > > The implementation of strscpy() is more robust and safer. > That's now the recommended way to copy NUL terminated strings. Reviewed-by: Tony Luck <tony.luck@intel.com>
On Sat, Dec 03, 2022 at 02:19:32PM +0800, yang.yang29@zte.com.cn wrote: > From: Xu Panda <xu.panda@zte.com.cn> > > The implementation of strscpy() is more robust and safer. > That's now the recommended way to copy NUL terminated strings. It should read "NULL-terminated strings". Thanks and BR, Ricardo
>> The implementation of strscpy() is more robust and safer. >> That's now the recommended way to copy NUL terminated strings. > > It should read "NULL-terminated strings". Both "NUL-terminated" and "NULL-terminated" seem to be used in the kernel source and commit comments. NULL is ahead 124:45 in the source, but it is closer in the commit logs where the ratio is 129:76. Single "L" NUL seems technically more accurate as the string terminator is an ascii NUL character. From man 5 ascii the character name is NUL (though the description says "null" to muddy the waters) Oct Dec Hex Char ─────────────────────────────────────────── 000 0 00 NUL '\0' (null character) -Tony
On Wed, Dec 14, 2022 at 09:29:59PM +0000, Luck, Tony wrote: > >> The implementation of strscpy() is more robust and safer. > >> That's now the recommended way to copy NUL terminated strings. > > > > It should read "NULL-terminated strings". > > Both "NUL-terminated" and "NULL-terminated" seem to be used in the kernel > source and commit comments. NULL is ahead 124:45 in the source, but it > is closer in the commit logs where the ratio is 129:76. > > Single "L" NUL seems technically more accurate as the string terminator is > an ascii NUL character. From man 5 ascii the character name is NUL (though > the description says "null" to muddy the waters) > > Oct Dec Hex Char > ─────────────────────────────────────────── > 000 0 00 NUL '\0' (null character) Thanks for the analysis Tony. Indeed, I agree that "NUL-terminated" is more accurate. Thanks and BR, Ricardo
diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c index 100fbeebdc72..a05ac0716ecf 100644 --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c @@ -105,8 +105,7 @@ static ssize_t set_trigger(struct device *s, struct device_attribute *attr, { char *p; - strncpy(mce_helper, buf, sizeof(mce_helper)); - mce_helper[sizeof(mce_helper)-1] = 0; + strscpy(mce_helper, buf, sizeof(mce_helper)); p = strchr(mce_helper, '\n'); if (p)