Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8952217rwl; Tue, 10 Jan 2023 22:41:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXtTYn3IwKRzzE5JJ8olDeDni1byV/LlkxqGxX/ucDV6KA9oMQrVNPmJyqy0YF21FHZ2Ko7T X-Received: by 2002:aa7:d410:0:b0:499:d199:6614 with SMTP id z16-20020aa7d410000000b00499d1996614mr3502519edq.36.1673419268780; Tue, 10 Jan 2023 22:41:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673419268; cv=none; d=google.com; s=arc-20160816; b=wbS0aeLDG+kch2fOPJIQ5mqkf93ZbZv6SV8y2+PD0ARpTI/eBh1aIRMdiuP7WeG9SY mA5kbAXszPA2+Rzi4UWlYxDwKJeORcYS0XwHKh6QateCPUT5Q3xWiA4O3P6C/bBj370p FITTMGhf7PxBfPyq4FA+q8qmMSB4jd8ihjKx8Kpr9fSkC5LSzxfsNf7NKCBu8E0n8YE/ 03Kx/P6J1A2Q9MRiy1RTu0vGYdzTtQNCLHWn+IAQEc3migIhs4wD5AwUAhtcziW2D00w SJ/7YCpKzYcwz8XFajkXnmcq1lDiBtK5OZ3SwfN1t9+5+sGKEunVrAdq8YVPh8CC/NBj +YYw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he36-20020a1709073da400b007a4feae7adfsi15642007ejc.565.2023.01.10.22.40.55; Tue, 10 Jan 2023 22:41:08 -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 + 55 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?B?W1BBVENIIG5ldC1uZXh0IHYyXSBuZXQvcmRzOiB1c2Ugc3Ryc2NweSgpIHRvIGluc3RlYWQgb2Ygc3RybmNweSgp?= Content-Type: text/plain; charset="UTF-8" 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 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)); -- 2.15.2