From patchwork Wed Jan 11 06:25:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 41763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3156751wrt; Tue, 10 Jan 2023 22:27:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXushoUNGahCpMpHRuAntwCFwga0t3ulp0EIQukLMDct5xziigqdDA2u/cZn9q9AaOI4Z1KB X-Received: by 2002:a17:906:99c7:b0:7ae:b637:633f with SMTP id s7-20020a17090699c700b007aeb637633fmr81990061ejn.4.1673418467321; Tue, 10 Jan 2023 22:27:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673418467; cv=none; d=google.com; s=arc-20160816; b=IkVhWQT2K3YtbVtAKpOsP6Fkn+CsAklCwecYqzPogSf/rBrcfKuJnX/nHikkR/kYdp puIxcPbh/sn2YMzcg2UODHv3rRRghr1b/6SypSUnRBcfBST+sTHYclYze/lLAQKeQl5w Z/Lidlx4Hnz1XRLb37qI3CuxGuv2kKYbYq+aEJ4uBSQ1BvMPWxg4l17l99PpNJBaPJy1 MupvygOZ1YyVkuUQZhNi+2hD06zl/dNvAwnUofozGQKvdZ+W+9BkXn/EDbaMv8WnW1Zr z5ck6FjDVA40FsquBrZ0xwEsI8iQ6fFJ6wLO6sJZXRB0fXtoMhx/xu43VyrATzCzNdxU w8aQ== 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=HSaQbFEpkF8rj56HQeQPMDZyCt/oZGTE+zAvNEjfn7g=; b=MVv3+1nB/n0xbg1aFNiJGpStXznqdM8Joo3JabZt11fSnmc9XrVmNWBUdpR38vo3JU aSH+78gCkNTlmZGb17y4XV+ve9B2oBNni8YzLWwVo6kfCnNXV70sIxVEhnk+wF6hOztO nfDll9yIePP6N5+OnxnB4wNdaLqM5uq8bwn4l5azfG9hzJ4mpErqn5keyZshYWkfvYf+ LGw6KUElb0j3N4XFQYprPqcKO2tI13438adQdpizWDUtTCSlnHYf0nzdhTdfEowYlgws A/W8YHvVduJtQiPcQdnnU+KKfafBz+XxWYmlUApBktV0GwQSaomN3KIKJQh8J2L4ea8h IOSQ== 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 wg4-20020a17090705c400b007adf3ed5d20si14310593ejb.376.2023.01.10.22.27.23; Tue, 10 Jan 2023 22:27:47 -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 S234554AbjAKG0V (ORCPT + 99 others); Wed, 11 Jan 2023 01:26:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbjAKG0C (ORCPT ); Wed, 11 Jan 2023 01:26:02 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04241EB0; Tue, 10 Jan 2023 22:25:58 -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 4NsHkD0k8sz8RV6K; Wed, 11 Jan 2023 14:25:56 +0800 (CST) Received: from szxlzmapp02.zte.com.cn ([10.5.231.79]) by mse-fl1.zte.com.cn with SMTP id 30B6Pkjg075836; Wed, 11 Jan 2023 14:25:46 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Wed, 11 Jan 2023 14:25:48 +0800 (CST) Date: Wed, 11 Jan 2023 14:25:48 +0800 (CST) X-Zmail-TransId: 2b0363be566c67d92096 X-Mailer: Zmail v1.0 Message-ID: <202301111425483027624@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , , , , , , , Subject: =?utf-8?q?=5BPATCH_net-next_v2=5D_net/rds=3A_use_strscpy=28=29_to_i?= =?utf-8?q?nstead_of_strncpy=28=29?= X-MAIL: mse-fl1.zte.com.cn 30B6Pkjg075836 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 63BE5674.000 by FangMail milter! X-FangMail-Envelope: 1673418356/4NsHkD0k8sz8RV6K/63BE5674.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63BE5674.000/4NsHkD0k8sz8RV6K 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754706442661145416?= X-GMAIL-MSGID: =?utf-8?q?1754706442661145416?= 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 - Use the returns of strscpy to make the copy and the preceding BUG_ON() together.Thanks to Jakub Kicinski. --- net/rds/stats.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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));