From nobody Mon Apr 27 16:11:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BE39C433EF for ; Fri, 10 Jun 2022 18:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344640AbiFJSC4 (ORCPT ); Fri, 10 Jun 2022 14:02:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241580AbiFJSCx (ORCPT ); Fri, 10 Jun 2022 14:02:53 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DAC626D0 for ; Fri, 10 Jun 2022 11:02:52 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id j11-20020a05690212cb00b006454988d225so23202312ybu.10 for ; Fri, 10 Jun 2022 11:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=8g7Zznczp6I1sznUOMtSobsOu1cIZ/e72E9w80VeXUA=; b=mWg0NGJHeZ7Yf11l850PcdthCWlBwlDIQrQTER03M5lVTm1ahubqqCNCTMEkDx/T2x vdVCrEIHvZ/PsfuKzrZToRDTRznJlarZxdcP37hlFYseIMIy9Gsf6dMUmzIDV+5wfY0d dke9s4uU/U0qsVEuhuVSuugQkySSDWLlZa+83G1qp4VrTkSxMCs/KT6fK3rC6X8m3Aay dhOXjzG3iq+IEE1z166y9N6d3e3Udzas6TA0lT9yOo1VzRwloEoE+QgbvAG2AeoOV8WY Z08D7fRBdKDj9ITQHA5tHo3yH/qNbw+hxrYpHu4dHoqz9vWclmJZWdCbz+lZ7HR/VqSY uwyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=8g7Zznczp6I1sznUOMtSobsOu1cIZ/e72E9w80VeXUA=; b=WKf6ggybcJ/quR1cX/mkmeG94HTSWeTLF/7mXuQpftvd8APZ3ZNRMm3XiMIcyXvaco gx+h5p571PkdnMzhdiyzxPiD47CgpY2B3MjBrCb2Vcyk51qHOCcJINQckhY7UnacbMLK o/HM9pcfnBup9OkR3uwl+3Fpk7b5ZE/g6+yXLhJ4lDLD0TP65SlCvyjdXyfaU7l+v4jE E5fL1ZrEFfHI/OFrdU3drLGjtracp+pZN/4/6Xd8ROzctJM/h8aQRL5qNx7fIi1hUEQP dDjJb15v1KX1yxp0xpphzdjlRbjdgYHQQXkF3kM6k/wFLaC7KATD305498SV2OOyb179 RBNg== X-Gm-Message-State: AOAM530iP3OW+wnKGb89Ctf2dUz2EPtOR9Nh13Q53zbaFWNhebL05byE i/tE030iDCHsSqiMY9kElsiAWtZvl7MK X-Google-Smtp-Source: ABdhPJyYij0RTjOXOmw32oNm8P6w72IfCLTo4nLil7GAoKLwPKaB6kFOTzsggKRIA78rKr8Csn6Kr0qkGjeE X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:70ff:220d:425a:78ab]) (user=irogers job=sendgmr) by 2002:a25:cec6:0:b0:65c:98f5:a06a with SMTP id x189-20020a25cec6000000b0065c98f5a06amr45393202ybe.355.1654884171558; Fri, 10 Jun 2022 11:02:51 -0700 (PDT) Date: Fri, 10 Jun 2022 11:02:47 -0700 Message-Id: <20220610180247.444798-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH] perf test: Fix undefined behavior in bp_account From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix: tests/bp_account.c:154:9: runtime error: variable length array bound evalua= tes to non-positive value 0 by switching from a variable length to an allocated array. Signed-off-by: Ian Rogers --- tools/perf/tests/bp_account.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/bp_account.c b/tools/perf/tests/bp_account.c index d1ebb5561e5b..6f921db33cf9 100644 --- a/tools/perf/tests/bp_account.c +++ b/tools/perf/tests/bp_account.c @@ -151,11 +151,21 @@ static int detect_ioctl(void) static int detect_share(int wp_cnt, int bp_cnt) { struct perf_event_attr attr; - int i, fd[wp_cnt + bp_cnt], ret; + int i, *fd =3D NULL, ret =3D -1; + + if (wp_cnt + bp_cnt =3D=3D 0) + return 0; + + fd =3D malloc(sizeof(int) * (wp_cnt + bp_cnt)); + if (!fd) + return -1; =20 for (i =3D 0; i < wp_cnt; i++) { fd[i] =3D wp_event((void *)&the_var, &attr); - TEST_ASSERT_VAL("failed to create wp\n", fd[i] !=3D -1); + if (fd[i] =3D=3D -1) { + pr_err("failed to create wp\n"); + goto out; + } } =20 for (; i < (bp_cnt + wp_cnt); i++) { @@ -166,9 +176,11 @@ static int detect_share(int wp_cnt, int bp_cnt) =20 ret =3D i !=3D (bp_cnt + wp_cnt); =20 +out: while (i--) close(fd[i]); =20 + free(fd); return ret; } =20 --=20 2.36.1.476.g0c4daa206d-goog