From patchwork Sat Oct 29 02:59:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 12624 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1157571wru; Fri, 28 Oct 2022 20:10:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vEFO6ZuTg7PMjare2/nvSU/pww0fCJWbomtNb4J7993noLjPFfgTsAQUwnN4Xq1g72knN X-Received: by 2002:a17:906:846d:b0:7ad:90dd:4b6 with SMTP id hx13-20020a170906846d00b007ad90dd04b6mr2107987ejc.492.1667013035707; Fri, 28 Oct 2022 20:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667013035; cv=none; d=google.com; s=arc-20160816; b=tYh0BstAAJRoc6g+265GnP6Z5+PIQFIYVtU4w0fDYSfHeShJ3NZPiH7F9iPrnRF8Rj fgj7O3KZ+Mp9wq43O1etcnIMF+lSz3Vdzjwai0X0OUuVIaZGMFayU7hyOJe7gdv1uba4 IBw0660gMHmx51fmLIg6K7akIBqn0ZhpWUD/KVuAeqiSOKpHa0GdUBAHyaG8x3tpi8yi XGt5HJnuDE09WwG7FVUCia4STFCgJCtx3t90fHKJcTzPhNMDUlUYsZwMEtG9bjhlNFme XVsUiwqJpRPP5gNFlwWDn7siMdpbjYupmDgxxytKRV0cLp9KpHAajUMpbG4a+IXCRPUo iAfw== 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:date:subject:cc:to:from:message-id :dkim-signature; bh=yzgljApEq0qdIxlgB5hEgOKNze+VaVoW3rIffIgUM7U=; b=cXjCpB3nSbDNvjL6idKuU02i4iErWULnItKLk1QDHZKr2Tj5rryWFGVegSSejxjRf/ 56PiempDBkkXGvVov/Ntbjhp4H6/0seSFY2mA1i8gKLl1Gg6DES2J0b5ALueT/PSQuln pI32sRMN3Q8WYtQoXPIhY5d43vzNv0vKkj3rRz5xzqsN4spWOdvb9lIaZt69LZ3o1ltg Jp8BPxCI/B1XByvGOiMGt7ST4uiL7ItKXViNWhklmQWNEJ89DlajFlqzqPeEtuAHz7Ob fwDbU/FW4YpMVFjlGhX9t5DR5ottF8ZmaquKRnJds6CdKWfkTI+JJqwnjUDcBEnfFwM2 zuLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b="u8XStJ/m"; 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=foxmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw19-20020a170907a0d300b0078ca7bbf616si134553ejc.746.2022.10.28.20.10.10; Fri, 28 Oct 2022 20:10:35 -0700 (PDT) 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=@foxmail.com header.s=s201512 header.b="u8XStJ/m"; 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=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229885AbiJ2DCY (ORCPT + 99 others); Fri, 28 Oct 2022 23:02:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbiJ2DCS (ORCPT ); Fri, 28 Oct 2022 23:02:18 -0400 Received: from out203-205-221-233.mail.qq.com (out203-205-221-233.mail.qq.com [203.205.221.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2C3C391; Fri, 28 Oct 2022 20:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1667012474; bh=yzgljApEq0qdIxlgB5hEgOKNze+VaVoW3rIffIgUM7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=u8XStJ/mQtG2DbJzqxABEYYRn3RnlpfZl4iB5O2tysvAKpTEzinx5DO6fFT47PnV/ t8wNRmmYDdmUkQfLKLL9JT1QwqXIFRfwVBN6mtGRuiBk3lEXbbIlhVYIzRNmM3ii94 jjbz40kaf8w6MdmWABToAENaGwbigjC+QEhpkRpk= Received: from localhost.localdomain ([111.199.189.86]) by newxmesmtplogicsvrszc1-0.qq.com (NewEsmtp) with SMTP id EF589CDA; Sat, 29 Oct 2022 10:59:53 +0800 X-QQ-mid: xmsmtpt1667012393tuia2uaof Message-ID: X-QQ-XMAILINFO: N7h1OCCDntujuAp5mqx8XHGzuesj9Bu6ZPwpAViukBow+hzL2HWcPWqqa7gFMF TjhfQifJ/YvXVwrMpYQyf6ofAAzK/brsjY06p8SpPd5uVP6GMj6aaz6xZL8buLBLWB0RMG3gEo75 OkdpKSRIHWtxIwsJdMjY3nZwLOAG/qMXjcIG5L8UJ2+LnsixUYEBogcjXAarsWns8kozvihdQpf0 43wJLOgWCZYWekP8pcF26gnMhDIUfbOgQJZiAAcWDaqzwmOa21uXFTrcqgJaMibQo5voqFxdZvPP p6qX+NDPF3iUrZMJ88Zo1RCxgdaw5N81pwZpN+th/V/yr+0I+sGOhQc0JcrF7IdDld/vem2qhUUt +Y6u1SyPmQG2k0Wy0SBpGgv5GE58o+iPJwIYM0eAWHHgENdXPNM6c2ASU30Dzx2HHRfnA4sWC/9B hzHPLyLPpDddB2Z+Iu9GYZJvgfNfvtuzpVjE8oFXfn/W1umv2O9NJWBSegOZJPL9iEVp4vWMCXqa um6mu/C+ENQu6J9+WbtojzAugRwaonmwKq9q41lFkbs1WazAJvbEiC3b8I259pKjH/8jInKCFEpj 1R7yjCIsXZoTlYjgFuYITYFpzuB2rdR5ZZlhyCdNoc7YYGP60KhxozLd6eHzGc8bHAU8s0EEUXU+ 3ZiM0iCJn8DSpLCrdPn+vPjyYWhjIqD+uiBHlBTf/WHc6D7ARlUZO58gJC1BS/mVAX6hWHfPQWV4 KGEQfW1BA8IxxZBeDDHHxzss/uut7Zt5IhhVJfanPpeuvyX6Eyhgod2xv/IKr304uRVjcP2MQTfz PdyIakpKOYP8dVRLLP8ll5m/ily4Db7CwtzX8gPW/KxeRA+B7J38upFGowraPuq+0uRrydWkKw6A ma2c2Nfyxf1MluIkG4lU4Dg3vAUdclxPRaEmfPcJISemCf00fPC5Zlv/Lx63fP/uMrKWpH3tj/ML Vs301TZKX3YvlPMWDGCN+5QsXEPcERWc7IQIJ/a3TWiKILkrL3ELaaLzpBLHkl2ZE4a0ll93s= From: Rong Tao To: andrii.nakryiko@gmail.com Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, martin.lau@linux.dev, mykolal@fb.com, rongtao@cestc.cn, rtoax@foxmail.com, sdf@google.com, shuah@kernel.org, song@kernel.org, yhs@fb.com Subject: [PATCH bpf-next] selftests/bpf: Fix strncpy() fortify warning Date: Sat, 29 Oct 2022 10:59:52 +0800 X-OQ-MSGID: <20221029025952.22566-1-rtoax@foxmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RDNS_DYNAMIC,SORTED_RECIPS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: *** 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?1747841326605338612?= X-GMAIL-MSGID: =?utf-8?q?1747989861101753931?= From: Rong Tao Replace strncpy() with strncat(), strncat() leaves the dst string zero terminated. Compile samples/bpf warning: $ cd samples/bpf $ make ... In function ‘__enable_controllers’: samples/bpf/../../tools/testing/selftests/bpf/cgroup_helpers.c:80:17: warning: ‘strncpy’ specified bound 4097 equals destination size [-Wstringop-truncation] 80 | strncpy(enable, controllers, sizeof(enable)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Rong Tao --- tools/testing/selftests/bpf/cgroup_helpers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c index a70e873b267e..912e6522c7c5 100644 --- a/tools/testing/selftests/bpf/cgroup_helpers.c +++ b/tools/testing/selftests/bpf/cgroup_helpers.c @@ -77,7 +77,8 @@ static int __enable_controllers(const char *cgroup_path, const char *controllers enable[len] = 0; close(fd); } else { - strncpy(enable, controllers, sizeof(enable) - 1); + enable[0] = '\0'; + strncat(enable, controllers, sizeof(enable) - 1); } snprintf(path, sizeof(path), "%s/cgroup.subtree_control", cgroup_path);