Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3325967rwi; Fri, 28 Oct 2022 20:13:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4I1bb2BLGWSfvnej3waqknyK+5aha82HFmu/LP+xjinay066e6983yE1ZN2U/WmopeNgik X-Received: by 2002:a17:907:72d3:b0:791:a4fa:c4ac with SMTP id du19-20020a17090772d300b00791a4fac4acmr2125818ejc.391.1667013209923; Fri, 28 Oct 2022 20:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667013209; cv=none; d=google.com; s=arc-20160816; b=Re/cMvU4QbdchIjrD72Q0sHVJ+DrqihtvHoujjKSKtatZRCGch8uRGtPBMEVadzp7+ gz3/4eZM4L1v5aBbyLRdAGu0jxH7oazu971YqCIfjLd5gD8RcJz3T7ME1izYxZWr6l22 xVDziXhJKv21j7B3ZcoT6vjVvqnO9uvrN2oK5xr3BSjkGKk1f6/CLwHqo1zdUWVig5qf oCkyve4OHEZ3fw++G5nwzEUz/ClyVAP1tqdNoIjJfkEOLtsLpqBa7T35W9+C/QJ9JU9I a/aETimAsQdyoAr+FMgudj0MzNF6v3oC4cGEjs8IOwpFBtD30WCITKYPvPb0pj1OPQGe lzVA== 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=c8DKeSJHy7nv5V+vv7J8kQrLnkZeHMgYOuYV61olSO4=; b=mRk/ejZ2LsrMUeZEXn4KeA6csXVIT/P1rlkKExy1f5fpZcj2LcpsnKht/4gekww0yw UL9rGUGdJ8r78C8bsqCM474WQElt/qepEzMbL7hKA/WfbpAX/HsGQfV+adn+04YsrMX0 6bf8ppgYILONCTqreBhF7CXTZbJ1fOnZjEYZCzHUV3DeFaV8eCGwNqtJ9Q8CrghARyIw 1h2ZVh+j1ZD3uW41XPtfZ6l5k4grNSxQ8lzG7VJiaThy2wkaYS7gblotxDv4dYJPDjga yZcGVS3LibvnrW0xhlKSvnECvqoMBdiRgJ9lczKa+DAzyue6M1hBNrGOkLvcMiAE4GvB e+xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=SE3D05l2; 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 hq13-20020a1709073f0d00b00779a07b4e90si568359ejc.711.2022.10.28.20.13.04; Fri, 28 Oct 2022 20:13:29 -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=SE3D05l2; 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 S229752AbiJ2DJn (ORCPT + 99 others); Fri, 28 Oct 2022 23:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiJ2DJL (ORCPT ); Fri, 28 Oct 2022 23:09:11 -0400 Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80A231C7110; Fri, 28 Oct 2022 20:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1667012944; bh=c8DKeSJHy7nv5V+vv7J8kQrLnkZeHMgYOuYV61olSO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SE3D05l27H4Wqqd9BFHOCeIN7gVyIZ1ITbKps7TVRfxzmKcTqJM9KSpmoXqQuyhEh mWhzsfaF/kPLRKQpJBa1kOSopDaRO75V8NvnSIVXpS9MAQBEbKEYyJ7DQj6gkkAwO0 FV09Ezu8eoBJqxeXRDjTsKo0zbr/teA+ucOR/6YQ= Received: from localhost.localdomain ([111.199.189.86]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id 1EE9CAFF; Sat, 29 Oct 2022 11:07:46 +0800 X-QQ-mid: xmsmtpt1667012866tszdu6uwh Message-ID: X-QQ-XMAILINFO: M5KH7ZjKOjx4y5ReN9Ig/rkL+0Hdd95Phowszp3b8X0t9jtQIK/Tmf8UovW4pj 2pILr1dmXvV9WdTOEEXIajKMZfAfcnVUKbnosj7k4TzakQC9qSEYk74EMq0ZO+toWT2O3SPvbmgh DWlOVi+nEJOnuKEQtzkPKwvfGud8gRvsoKyqQyZQtIJTCYvBX3d6LoSUrXbuTcIWlAsNX31gXOLM oDGyz6kWukIIEtiKTxfwI7xScBX1ny9vIwv939+Ll5Uteg2P9WVMQ7qdYzrD+IVBuQv+veFVlTaB uXbTN7Akr3o4pJkd8hf9lCFkLUojtGfHoU7c/XTRdz8T5AephBAg9p/qcDZGSOjACla9xn1DpLha o+HMxY4dsZZL4WJMrr9tmm7L7gQzIBNpX++JTleScZ88+XqWaC8xrWYjbrInptBvGySwSE0gCXy9 oFZBAjQbykXcmPR6i8/Ey7w7SRIrFBtcoerdwL773lL0v91BJtvuimfmZgmzP0+MIsO4JQHbO8jx EpmrEoMzZn2g/iC5lWqZ00/xtukjBhDGU/sdgosfvo9pVB2Geno/HtOw9vGLNtBXx7PCONIafb67 IfvOzuHs2HCNpIn7SbFgzwR4VaS/+SWzSxK36EpcRXv3TM7/iuQzwz7KeZtk4HIzMCZY8DmTkBTJ bx0o6tvr9LJ2yrcv0Gu24ba8JwSAXS32IkGIHtQRzaPPRnpZ+8SCJioorTw+lCPMTC9boWqUet0m Sgw98kj38wXUdXEU4L8o1EKBKX9VwE5kwnIGS80ETOj8q3z9OA/QPDC8dBF47aQVH8KLVDHwiJ3H a3tbL7Et9lyTFXgL5paksucNePksbwBVUVCjw/oRv4qEIiw631ci9bRNEyC1HYCKISJH2k8u3aCZ S2sgct1zUCnotBzFuBcAFxA9Qn8/KqyVYFYM18h1s93piWkjCJnGZuMVZNqFPl7LI9z7k5V8D6rr dm9QTdxYZPKXok/t2JDZ0OtIVvBF76b852KDJ9bnQC4IWq4S8xjOVj1wRTrxV/sov5fQHhAeOkqM M3h+BAtR+8I9XxdRyjLZNLPquVFOdmZmqAUhJ+CWtKCZKpI/psDeqNa5da9+w= 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: [RESEND PATCH bpf-next] selftests/bpf: Fix strncpy() fortify warning Date: Sat, 29 Oct 2022 11:07:45 +0800 X-OQ-MSGID: <20221029030745.25588-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 e914cc45b766..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)); + enable[0] = '\0'; + strncat(enable, controllers, sizeof(enable) - 1); } snprintf(path, sizeof(path), "%s/cgroup.subtree_control", cgroup_path); -- 2.31.1