Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3324273rwi; Fri, 28 Oct 2022 20:11:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CkvCS+L7uxfib+nA+NVBaxOJsxjfsI+WzRRL2R+Z9V+AjIZ53lJksY74Tsjo/URk2nTvO X-Received: by 2002:a17:907:7f8b:b0:7ad:b45d:4e9a with SMTP id qk11-20020a1709077f8b00b007adb45d4e9amr212919ejc.421.1667013086338; Fri, 28 Oct 2022 20:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667013086; cv=none; d=google.com; s=arc-20160816; b=H+jMixwXMPm1ZEyRt3wEiccpELcR9s3QWNerfGRMgWogFOIeN/bF/Gu/e+glE9Ipxn XwNDKCUtRy/p1bGLWyREYCQftlO5ZgO6rMd1zJHvK0km5FoD395lruCrzRtRvlHU95Bz PbNn5l9wAdF3FA2PjRLqLb5oDB31tJHUr5aK0kPf9ti1QJnO45yU2Am56LkjcCQgakTX VmO8T0rtMvo/igbDUhKBHEtiqX9MwfqPoHDwttyuHCr/CJ/IWKgAGQtrRpVJHvgH/UD0 Yi26X+AtwcpAHCz7cyiaA1mappl3rqK4GzmBR9g9o58MMmYqSHI101p3cQtBcPfCXCTd MjaQ== 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 Return-Path: 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.11.00; Fri, 28 Oct 2022 20:11:26 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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); -- 2.31.1