Message ID | 202301091946553770006@zte.com.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2108536wrt; Mon, 9 Jan 2023 03:50:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXtW1r2mFOBYvoozQZz33lix7Cvo0dadZq22eu4Xk6mVmB0fd2jsugHyy1U5AB37Q6Z6Qr+9 X-Received: by 2002:a17:902:b78c:b0:193:1fc5:f611 with SMTP id e12-20020a170902b78c00b001931fc5f611mr6937377pls.38.1673265003368; Mon, 09 Jan 2023 03:50:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673265003; cv=none; d=google.com; s=arc-20160816; b=IpRBS4GJS9lw1/rx0RbiXboce8gYrtP76ulq+oE5qo6xIrQFUldyg72o8b+BYcA7iz RvBGDdOnIcZWAsBt1PrxptV95iZLFWSjHhvf+6eXHwBr4vqNVIUe9CLPO3r+nOSPDvYl 31inVuVjPCPTvCZRN8CaULflJ8HxLkeTjfcSGzSJhhIMZXdF2YSAG6qOm+xt+jUEadq4 UcVk/5PlXlSu3cuiUdzKwAutLLWiOiK568JQ53PMkVUj1as6MBro7IwItCEumbuVScGl afu7Q2Tc6r3xc1tgcf+ajcghYl0PBsUCLBtlwGEPhUSKPvmTY5L3uLlgNyp+KCOii1xr D56w== 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=Cxh/T4jfjLRUXA8f3qIMDXWhhWv5vokZw4+DnXiq9tQ=; b=IsoUpABaTq/xQL7QP++DmcD93CzNxy/GAca8QsRpaSHYmIlPP4+blToTQappkmFjSZ /lxOEY9lVGI4XAK0BJ9W43whKdyqMFGvr+8K4qMyzmtu6E8L+4z7moT6IWNNl+GPc7JE I9KQg1+g4TADRKWo4nwPWmHfxLren9Xd/G4CAaiidfBQ2nTi/n5NdqOBVTuIYHkSrB4l CooD74e9byUmn9u2RUhjd8G655a+pe58P2as2x8As+0cIf/ynpXZromANmZOOrsHZkpy v5ZzYjD1lu2D20AgG+MdIi0o2Uzraz/pdMhegKR45T6UpQWJjUlqXt/vo7lx1j25dpFu n04Q== 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 p18-20020a170902ebd200b001933989d4f8si713842plg.344.2023.01.09.03.49.51; Mon, 09 Jan 2023 03:50:03 -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 S234353AbjAILrS (ORCPT <rfc822;zhanglyra.2023@gmail.com> + 99 others); Mon, 9 Jan 2023 06:47:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234309AbjAILrC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 06:47:02 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56034D136 for <linux-kernel@vger.kernel.org>; Mon, 9 Jan 2023 03:47:01 -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 4NrBxc0fcLz8QrkZ; Mon, 9 Jan 2023 19:47:00 +0800 (CST) Received: from szxlzmapp04.zte.com.cn ([10.5.231.166]) by mse-fl1.zte.com.cn with SMTP id 309BkqU1093359; Mon, 9 Jan 2023 19:46:52 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Mon, 9 Jan 2023 19:46:55 +0800 (CST) Date: Mon, 9 Jan 2023 19:46:55 +0800 (CST) X-Zmail-TransId: 2b0363bbfeafffffffffb62deb1a X-Mailer: Zmail v1.0 Message-ID: <202301091946553770006@zte.com.cn> Mime-Version: 1.0 From: <yang.yang29@zte.com.cn> To: <sj@kernel.org> Cc: <akpm@linux-foundation.org>, <damon@lists.linux.dev>, <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>, <xu.panda@zte.com.cn>, <yang.yang29@zte.com.cn> Subject: =?utf-8?q?=5BPATCH_linux-next=5D_mm/damon/sysfs-schemes=3A_use_strs?= =?utf-8?q?cpy=28=29_to_instead_of_strncpy=28=29?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl1.zte.com.cn 309BkqU1093359 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 63BBFEB4.000 by FangMail milter! X-FangMail-Envelope: 1673264820/4NrBxc0fcLz8QrkZ/63BBFEB4.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: 63BBFEB4.000/4NrBxc0fcLz8QrkZ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, 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?1754545523941828383?= X-GMAIL-MSGID: =?utf-8?q?1754545523941828383?= |
Series |
[linux-next] mm/damon/sysfs-schemes: use strscpy() to instead of strncpy()
|
|
Commit Message
Yang Yang
Jan. 9, 2023, 11:46 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.cn> --- mm/damon/sysfs-schemes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Comments
Hello Xu, Thank you for this patch. On Mon, 9 Jan 2023 19:46:55 +0800 (CST) <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. > > Signed-off-by: Xu Panda <xu.panda@zte.com.cn> > Signed-off-by: Yang Yang <yang.yang29@zte.com.cn> Reviewed-by: SeongJae Park <sj@kernel.org> Thanks, SJ > --- > mm/damon/sysfs-schemes.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c > index f0dabe3e2dc0..86edca66aab1 100644 > --- a/mm/damon/sysfs-schemes.c > +++ b/mm/damon/sysfs-schemes.c > @@ -353,8 +353,7 @@ static ssize_t memcg_path_store(struct kobject *kobj, > if (!path) > return -ENOMEM; > > - strncpy(path, buf, count); > - path[count] = '\0'; > + strscpy(path, buf, count + 1); > filter->memcg_path = path; > return count; > } > -- > 2.15.2
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index f0dabe3e2dc0..86edca66aab1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -353,8 +353,7 @@ static ssize_t memcg_path_store(struct kobject *kobj, if (!path) return -ENOMEM; - strncpy(path, buf, count); - path[count] = '\0'; + strscpy(path, buf, count + 1); filter->memcg_path = path; return count; }