Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1664381rwl; Mon, 26 Dec 2022 02:57:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXuNPv7na35L28YYoccRRvlh8mmXjgkOYqsCnAXn6KreEjDyZwg5PnQUA7OGMWcsFJk0pF2z X-Received: by 2002:a17:906:6b0f:b0:78d:f454:ba3d with SMTP id q15-20020a1709066b0f00b0078df454ba3dmr13402966ejr.60.1672052261116; Mon, 26 Dec 2022 02:57:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672052261; cv=none; d=google.com; s=arc-20160816; b=AiCOZzxHGMOmE07oto9Gq6H+uZHyDdq7WuzqggXm4TJq/fEAmIVsTgIVEn1XHdUWc9 zeJcisqmf8dLCCOvSIM9jtD/GYSj5WW14wcPGaOV8kOWCk9kArveqlsN/N8GFPnuLyTf uMbWAfjArH0MvTopjZnoxGT8Ddj3P7AGXQdljJnYGWn3Px2xtd+NVGfIW1eDNa19NL77 ZCYrTJk9bpcyuqCE2sIYQuLnNv1veoLHXgwtNkVYaKWKnpGqoU25U90mULKDHaPuNRJz F5KxU3uCz0KU7I+qoUkfVa2zBqhMJcqR+Z39ODPAXIvs7hHTgiD3He6aTo/ieQur8/J1 ApGg== 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=Vmd03RGiocuaCDfdnS1HmBsjNeFBkgVJLj8yqkMZn9Y=; b=ssOZ2+K6MGAWAj87OSp8uuPqN1MbOXbDpyJ94QAW+ZBBo4+jMNzBo+CoU3QIx1Smgl GCw27Qc97Qf+D0flvo3ObRfMNxOaLre/7eksPxs4BC9Xf8/f7Buk8DslbzJQYkBx3GN+ 7Tmqjbz0zzmfR3+8wyKRFMhSZJ0otznfp2A3zYKt81m57wtusfLu3fU8tlIqcWUYERuG 0zMsq4iKO8OU9b+5Mn9ld8NFi53G7N8OoTd7brDCS+lLOQssiDLC9lQ5TUAhgIMmXYbt mncaBd3HdbiEIau/n5Tqkb9ZJZq5ee+hUL6ZXWik7TWliKoQARJ6UTlNzUgKf8MWBzEd DsJA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g19-20020a1709065d1300b007c0eb33879asi8709080ejt.667.2022.12.26.02.57.25; Mon, 26 Dec 2022 02:57:41 -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 S229999AbiLZKkM (ORCPT + 67 others); Mon, 26 Dec 2022 05:40:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbiLZKkK (ORCPT ); Mon, 26 Dec 2022 05:40:10 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA6EC10DF; Mon, 26 Dec 2022 02:40:07 -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 4NgZ6s5zfdz4xVnH; Mon, 26 Dec 2022 18:40:05 +0800 (CST) Received: from szxlzmapp01.zte.com.cn ([10.5.231.85]) by mse-fl1.zte.com.cn with SMTP id 2BQAe1xc048557; Mon, 26 Dec 2022 18:40:01 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Mon, 26 Dec 2022 18:40:04 +0800 (CST) Date: Mon, 26 Dec 2022 18:40:04 +0800 (CST) X-Zmail-TransId: 2b0363a97a04fffffffff67e1b98 X-Mailer: Zmail v1.0 Message-ID: <202212261840048448622@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , Subject: =?UTF-8?B?W1BBVENIIGxpbnV4LW5leHQgdjJdIHBhcmlzYzogdXNlIHN0cnNjcHkoKSB0byBpbnN0ZWFkIG9mIHN0cm5jcHkoKQ==?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl1.zte.com.cn 2BQAe1xc048557 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 63A97A05.000 by FangMail milter! X-FangMail-Envelope: 1672051205/4NgZ6s5zfdz4xVnH/63A97A05.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63A97A05.000/4NgZ6s5zfdz4xVnH 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 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 v2 - sizeof(in) is better and simplified, thanks for Helge Deller. --- drivers/parisc/pdc_stable.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c index d6af5726ddf3..d3075445260b 100644 --- a/drivers/parisc/pdc_stable.c +++ b/drivers/parisc/pdc_stable.c @@ -274,8 +274,7 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun /* We'll use a local copy of buf */ count = min_t(size_t, count, sizeof(in)-1); - strncpy(in, buf, count); - in[count] = '\0'; + strscpy(in, buf, sizeof(in)); /* Let's clean up the target. 0xff is a blank pattern */ memset(&hwpath, 0xff, sizeof(hwpath)); @@ -388,8 +387,7 @@ pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count /* We'll use a local copy of buf */ count = min_t(size_t, count, sizeof(in)-1); - strncpy(in, buf, count); - in[count] = '\0'; + strscpy(in, buf, sizeof(in)); /* Let's clean up the target. 0 is a blank pattern */ memset(&layers, 0, sizeof(layers)); @@ -756,8 +754,7 @@ static ssize_t pdcs_auto_write(struct kobject *kobj, /* We'll use a local copy of buf */ count = min_t(size_t, count, sizeof(in)-1); - strncpy(in, buf, count); - in[count] = '\0'; + strscpy(in, buf, sizeof(in)); /* Current flags are stored in primary boot path entry */ pathentry = &pdcspath_entry_primary; -- 2.15.2