Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp366701rwb; Thu, 12 Jan 2023 21:36:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXv+ydTRFRETcPWAlDJQwAyY6KKz45wtQlaNucJcr5j5qEjo/U1Y1h/KLbrRiFNJOvR/ThtJ X-Received: by 2002:a17:907:a788:b0:7fd:ec83:b8b8 with SMTP id vx8-20020a170907a78800b007fdec83b8b8mr69425600ejc.19.1673588169396; Thu, 12 Jan 2023 21:36:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673588169; cv=none; d=google.com; s=arc-20160816; b=fesaZ08Zgj9IOwnOtrl8SjthM/PPnkzvINRY9qKcnm3Lmk2VbuGKd4ZI9YbvEb7+XI NVa9AaFdzT+aBGm1RXpqjOe5mr9AwlFCAMhSSvWR4H3IL0R6ph09Tc3kM5peulYrKbNX 1JRKy9oM0hIh0wMCoFavezTzy9Efc82hIgoEbSgBeu89rF9qNRtvtDMd6tB/ahDeSUiQ xOLZhsfPY/unQJLymlJtluTXg1rGY4CEyTLGbEU4ONbGv0kxOr79mNTDHaLIXpjGUEpz 6b7EB+moGTLdInDKFJch+1v00nDTMYx0hv/8sLsRv2MYANgttrnmssksLufTGzf89ZfI Jm3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=dGPFwbAstILw+OG7DQulEhjkqha+00JtjhW1C7v2/Vs=; b=ixT3Rzo856rTKvSt8i/YkfCxCV5ZwiCtMIgxXife/UPSw+vfxqCIi+AfHF1rTKpv3i U6rJBJsvJdCQ9qynqvW33gwCYuIgIiDVWpWaKFLDa6Eo+13dTAPwp8gC/IgPE9iB0w6P WUK1hNZLyde76jDF5E87RTxuAa/l7QY1KahB1mGNGrnhdKe57CfyRqX4nUaEW8D7JO6H 333YRDpm/9Uk9/W6mZWw6ww307gVWkeZCWXuTbmMzE1w90Bc+vlPMhEtMnVFmaGyb48y iWsXlS+ZKjPFUx3/b8OeE3lQ614TKKvJTb3GaNZkHULA/KoYJorDFHiBK6hyHY77VOHZ L5Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ciGEzOxe; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb29-20020a1709071c9d00b0084c04d15e97si10127094ejc.499.2023.01.12.21.35.57; Thu, 12 Jan 2023 21:36:09 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ciGEzOxe; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232202AbjAMFRP (ORCPT + 50 others); Fri, 13 Jan 2023 00:17:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231634AbjAMFRK (ORCPT ); Fri, 13 Jan 2023 00:17:10 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8F6CC7; Thu, 12 Jan 2023 21:17:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6BAA0621E8; Fri, 13 Jan 2023 05:17:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D131C433D2; Fri, 13 Jan 2023 05:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673587028; bh=XPE03f0st6e7dXiYlxulIsVQOCCHLqaGs+W0IsPREqw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ciGEzOxez/OCF4e08FgXfsSlitf1zK9otw5V4emI1RG8tRqTWcLyp4QiSgsmypjCu 3L/MYaimYDNYU1IzSfpiiPebb75nOLzOmjXdHYAPcMFlC7s8Vspz7cfvN1/XAmIpzN jTwL/EvTiU2MDvZRvhPe2hEEAUV1k5cmAoDKa8TnuY04n71mNxMsS9bmdOT5Xl9gLp LaVKtQdrCgAJiv4zyfRtjZjjRe5mP6pmL91MSzVbDJOVcgtg+qu2Zfu1XQKbUwPnlR asPazFo+t/wmU1cYwRk2tNxq/O9KcY39jjpNPctHZzX2YsF/yqKzHPCpFmb283ukwO UmrQji5jqZKfw== Date: Thu, 12 Jan 2023 21:17:07 -0800 From: Jakub Kicinski To: Cc: , , , , , , , , Subject: Re: [PATCH net-next v2] net/rds: use strscpy() to instead of strncpy() Message-ID: <20230112211707.2abb31ad@kernel.org> In-Reply-To: <202301111425483027624@zte.com.cn> References: <202301111425483027624@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 On Wed, 11 Jan 2023 14:25:48 +0800 (CST) yang.yang29@zte.com.cn wrote: > From: Xu Panda > > The implementation of strscpy() is more robust and safer. > That's now the recommended way to copy NUL-terminated strings. What are the differences in behavior between strncpy() and strscpy()? > diff --git a/net/rds/stats.c b/net/rds/stats.c > index 9e87da43c004..7018c67418f5 100644 > --- a/net/rds/stats.c > +++ b/net/rds/stats.c > @@ -88,9 +88,7 @@ void rds_stats_info_copy(struct rds_info_iterator *iter, > size_t i; > > for (i = 0; i < nr; i++) { > - BUG_ON(strlen(names[i]) >= sizeof(ctr.name)); > - strncpy(ctr.name, names[i], sizeof(ctr.name) - 1); > - ctr.name[sizeof(ctr.name) - 1] = '\0'; > + BUG_ON(strscpy(ctr.name, names[i], sizeof(ctr.name)) < 0); > ctr.value = values[i]; > > rds_info_copy(iter, &ctr, sizeof(ctr));