Message ID | 202301091948433010050@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 p1csp2110511wrt; Mon, 9 Jan 2023 03:55:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXsev9HFkliyRpFGlv2Ibw4D1TPS8+5S47NGcaLD3t8J0Yh6A1B7l/FHemC6SEaeQ2Groqvj X-Received: by 2002:a17:906:22da:b0:84d:855:dcfe with SMTP id q26-20020a17090622da00b0084d0855dcfemr11479957eja.42.1673265316028; Mon, 09 Jan 2023 03:55:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673265316; cv=none; d=google.com; s=arc-20160816; b=Q/P1IqBK+U0W1Qev+Cqt4ao0wOrJhOvsX+slyJaX54gbLZEtBuDTrvU2guys6E3rV4 rswSE6LpIn3Z+oPNmhzf1sw9fCjohoUT+Mm4/2hvmkmJjeKZXtdhkRv/8EG5iBTHj5Ri E+spNlpY8SJMvn982u78VezvvHx+GX78aqVSeDF7Nt39X6XUqf4o0jpZrenXnppNDaDj m4YAjB7QBCuWGQ4IDbUhjAPddOsK5iunhTxJyhYdsyQ3DYGaf5cvAc0OevAFFlTABNiB TI9AF3b0dT8vlhC6pO9gMvcxkCbBO5IWafwIfPpeNcSjNEfduUMJHD0ai86Sa8xCnCq7 VmCQ== 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=XGVUICpWVcIvOeTWCchQM7Tcr0OgyA4LuTojL88/be0=; b=czNWvofgZezPhKQzbLHhstQDJ25ZUYyGNU6F/d32wmkNvE+9g3x/qn034py2azMkYU fIGJUqpUus1bxCjOmTjg0HwyjO0fZrFeIlSIAmTOOqJCVoDvlsP8cw/fPCyUA1VQWIZr +eRMVjrk+U8/cF2Tb83hNnbOKKo1MKVuRxIsUhL0/pvh1DvrUxFxRyguOJemuE2nP8No IvTJalBNOiW6T+FmRtw3ZwKQtqovd5AQRgXylFHUhY7H2liwds5VXHJxSzj5IUX9xcGd r2UEZr8rIwnjnqWTMnDHTgZjQfdEyKEspLO9C0ODa7KSZI8ktkgFMmlIhF0jDFLyGPx+ KODw== 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 g25-20020a170906595900b007c0fd176698si7220892ejr.772.2023.01.09.03.54.51; Mon, 09 Jan 2023 03:55:16 -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 S236931AbjAILtE (ORCPT <rfc822;zhanglyra.2023@gmail.com> + 99 others); Mon, 9 Jan 2023 06:49:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237075AbjAILst (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 06:48:49 -0500 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18801D120; Mon, 9 Jan 2023 03:48:48 -0800 (PST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4NrBzc6Kznz4y3Z8; Mon, 9 Jan 2023 19:48:44 +0800 (CST) Received: from szxlzmapp02.zte.com.cn ([10.5.231.79]) by mse-fl2.zte.com.cn with SMTP id 309Bmers067416; Mon, 9 Jan 2023 19:48:40 +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:48:43 +0800 (CST) Date: Mon, 9 Jan 2023 19:48:43 +0800 (CST) X-Zmail-TransId: 2b0363bbff1bffffffffabae1a6f X-Mailer: Zmail v1.0 Message-ID: <202301091948433010050@zte.com.cn> Mime-Version: 1.0 From: <yang.yang29@zte.com.cn> To: <santosh.shilimkar@oracle.com> Cc: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>, <netdev@vger.kernel.org>, <linux-rdma@vger.kernel.org>, <rds-devel@oss.oracle.com>, <linux-kernel@vger.kernel.org>, <xu.panda@zte.com.cn>, <yang.yang29@zte.com.cn> Subject: =?utf-8?q?=5BPATCH_net-next=5D_net/rds=3A_use_strscpy=28=29_to_inst?= =?utf-8?q?ead_of_strncpy=28=29?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl2.zte.com.cn 309Bmers067416 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.251.13.novalocal with ID 63BBFF1C.000 by FangMail milter! X-FangMail-Envelope: 1673264924/4NrBzc6Kznz4y3Z8/63BBFF1C.000/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/<yang.yang29@zte.com.cn> X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63BBFF1C.000/4NrBzc6Kznz4y3Z8 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: <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?1754545852059940298?= X-GMAIL-MSGID: =?utf-8?q?1754545852059940298?= |
Series |
[net-next] net/rds: use strscpy() to instead of strncpy()
|
|
Commit Message
Yang Yang
Jan. 9, 2023, 11:48 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> --- net/rds/stats.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On Mon, 9 Jan 2023 19:48:43 +0800 (CST) yang.yang29@zte.com.cn wrote: > BUG_ON(strlen(names[i]) >= sizeof(ctr.name)); > - strncpy(ctr.name, names[i], sizeof(ctr.name) - 1); > - ctr.name[sizeof(ctr.name) - 1] = '\0'; > + strscpy(ctr.name, names[i], sizeof(ctr.name)); You can make use of the fact that strscpy returns useful information and the copy and the preceding BUG_ON() together.
diff --git a/net/rds/stats.c b/net/rds/stats.c index 9e87da43c004..6a5a60d36d60 100644 --- a/net/rds/stats.c +++ b/net/rds/stats.c @@ -89,8 +89,7 @@ void rds_stats_info_copy(struct rds_info_iterator *iter, 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'; + strscpy(ctr.name, names[i], sizeof(ctr.name)); ctr.value = values[i]; rds_info_copy(iter, &ctr, sizeof(ctr));