Message ID | 20231208000515.1693746-1-irogers@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5143234vqy; Thu, 7 Dec 2023 16:05:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfYN7EIGvwWcT6L2wPpGdEa4uUCvI+gGACgt+x3UDGDklEjShHG7183Lf98E1SwMjIg5hi X-Received: by 2002:a17:903:48a:b0:1d2:ec9b:92a with SMTP id jj10-20020a170903048a00b001d2ec9b092amr133237plb.73.1701993933948; Thu, 07 Dec 2023 16:05:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701993933; cv=none; d=google.com; s=arc-20160816; b=qF8F/zpHsJXmuWkDTdV+otWa+bfFTeb06VOaBNsGiOA+zBtLHxk1pz5tnOZJT7pXRk ybgNIt0hLV3CFB4S88jZ73HCiO3/SU7enGCi6u6UF2DKoW903CzBbfqgMYlJrEwHSinC rf1J3OJ5DyStL7h31fNJYvqac0UQmimlAh5KmrIvVQKAKnR5c7NZWWBcYbx3mybbgHOb 7gF5NrBNDl5q9Danjxc4wTpr52CoXeLpitd3AiAxMXVc/TmQpf+l4ZdStcbVKwd1hSrX FCklzij3NlGPP5n2+90n+Z2zISZR08upbAb8vHUMJWen1Q0u88OMlP8F0tKQ807dwaXL Vdbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:mime-version:message-id:date :dkim-signature; bh=R7VAKwLUWVywjDo2dEK6wuoDMXw70DBGya721KiihN0=; fh=TIE+Q456lum2w6CNS8hGW8/qeLzq5fdQr2L1Nx0bPN4=; b=EWmRp6eiQyogsqybK4foqyLCoeAtFjh1DKwcCxLL2+WlJtZo2ayVaTD4Hns5hM6W/n OCMCxHzCBQf8GfkUszAChpGnXD6vSpgqODEC4hCeODz/6M3QmxCY7QyKwFWGd3ZFBvEs y7uoinmockNlkTlUXffPNR6Bij86nxNscstcDTo8hgqb+I7PVuF5YwFRUIl0xFiPu8nB 6AP/dsH7oeFxCWg6txpm1cP+QfwPJIvgljPAos0Rlowq7l7NoYW98j8VvVdz70T5z5Yo A+X3PSz/SUmJ+RZfgfTgdAFFHNLYGjDG24oldjYwhRKujA1+K7h3biRNjXV7GrP4/G19 2/oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=x0tL1bBz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id n3-20020a170902e54300b001d005539ab3si549508plf.360.2023.12.07.16.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 16:05:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=x0tL1bBz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id ABF20833D547; Thu, 7 Dec 2023 16:05:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232505AbjLHAFU (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Thu, 7 Dec 2023 19:05:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjLHAFT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 7 Dec 2023 19:05:19 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C4751716 for <linux-kernel@vger.kernel.org>; Thu, 7 Dec 2023 16:05:25 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d942a656b7so18225337b3.1 for <linux-kernel@vger.kernel.org>; Thu, 07 Dec 2023 16:05:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701993924; x=1702598724; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=R7VAKwLUWVywjDo2dEK6wuoDMXw70DBGya721KiihN0=; b=x0tL1bBzPd2y1Arwym5V8VyRxX/wao6al+lRmd/1JaDyeGZUdKD62/YcJvRuJUOlJt 14icRm9QIXPNDjqpYb6oAJ1LDAlpBBMe1zGrThdDauLLR8I9/g1y3FagG5tTuFES0tKZ dy3i7UM/Bah6LHAQ5Shq7ZIMBgCycTZDn/3GSahtYsyOgdQbF86S7b7PbQV/wVkUgNsN EGzDezAKNBZHDhm2ebsPc9ypuaSOVbNagY96s7rJujQGUTiIT9Cd9QBToaCeZ+bdu8BH O++Tc7tf7YAQJFHLs6+4CIC9deqU8J1haQNNRkMYgDHCGwOp7wC5WzN7dHaS3jcA4nqD jwzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701993924; x=1702598724; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=R7VAKwLUWVywjDo2dEK6wuoDMXw70DBGya721KiihN0=; b=doaClfcoPbAZe8a7fFXxWrhQx7hoCXG9gS95YGF4k/nE2ThzTdjpblZaXlRH7gXvGn ZbG/ZZIviXCFzD7NFci1DUnd4t2Ahj1cGtkyeQgXmIYoAHuMtJmEQcqsztojm4hB5z0P 8bUbXHh9QCkh1eoMPBiEnb/FX3aoPx74MAK9BrRYvmDloO0oaEOZm2Crtu5E2Gbblrox vWQFSZsCPbfp9mVqDg+xo91Cz96lX27yurKv9ZR3avMhX4lWJACkgJZVigqmAcwV3anM HrIk3JGvBxUagjw2BGR3PAgB1zRrHhajKqlDHmf6TQ9wdH/qjVOd3YbC091QbPL7UcN8 3Uyw== X-Gm-Message-State: AOJu0YyjJbir1X8mYCZnH8Myl+pwwu9eVIancaFn9tYXVMPwlYgq8mP+ 8hbC6atz5bGFZ9khRxBeQjnUS7oTQN7S X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:aa27:6848:76cc:141c]) (user=irogers job=sendgmr) by 2002:a05:690c:4607:b0:5d3:9513:4aad with SMTP id gw7-20020a05690c460700b005d395134aadmr53065ywb.3.1701993924731; Thu, 07 Dec 2023 16:05:24 -0800 (PST) Date: Thu, 7 Dec 2023 16:05:13 -0800 Message-Id: <20231208000515.1693746-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Subject: [PATCH v1 1/3] lib subcmd: Fix memory leak in uniq From: Ian Rogers <irogers@google.com> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Chenyuan Mi <cymi20@fudan.edu.cn>, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 07 Dec 2023 16:05:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784669991472858862 X-GMAIL-MSGID: 1784669991472858862 |
Series |
[v1,1/3] lib subcmd: Fix memory leak in uniq
|
|
Commit Message
Ian Rogers
Dec. 8, 2023, 12:05 a.m. UTC
uniq will write one command name over another causing the overwritten
string to be leaked. Fix by doing a pass that removes duplicates and a
second that removes the holes.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/lib/subcmd/help.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
Comments
On Thu, Dec 7, 2023 at 4:05 PM Ian Rogers <irogers@google.com> wrote: > > uniq will write one command name over another causing the overwritten > string to be leaked. Fix by doing a pass that removes duplicates and a > second that removes the holes. > > Signed-off-by: Ian Rogers <irogers@google.com> Ping for this series, no comments since sent. Thanks, Ian > --- > tools/lib/subcmd/help.c | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c > index adfbae27dc36..8561b0f01a24 100644 > --- a/tools/lib/subcmd/help.c > +++ b/tools/lib/subcmd/help.c > @@ -52,11 +52,21 @@ void uniq(struct cmdnames *cmds) > if (!cmds->cnt) > return; > > - for (i = j = 1; i < cmds->cnt; i++) > - if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) > - cmds->names[j++] = cmds->names[i]; > - > + for (i = 1; i < cmds->cnt; i++) { > + if (!strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) > + zfree(&cmds->names[i - 1]); > + } > + for (i = 0, j = 0; i < cmds->cnt; i++) { > + if (cmds->names[i]) { > + if (i == j) > + j++; > + else > + cmds->names[j++] = cmds->names[i]; > + } > + } > cmds->cnt = j; > + while (j < i) > + cmds->names[j++] = NULL; > } > > void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes) > -- > 2.43.0.472.g3155946c3a-goog >
On Tue, Jan 2, 2024 at 11:30 AM Ian Rogers <irogers@google.com> wrote: > > On Thu, Dec 7, 2023 at 4:05 PM Ian Rogers <irogers@google.com> wrote: > > > > uniq will write one command name over another causing the overwritten > > string to be leaked. Fix by doing a pass that removes duplicates and a > > second that removes the holes. > > > > Signed-off-by: Ian Rogers <irogers@google.com> > > Ping for this series, no comments since sent. Would be nice to land this set, especially for giving suggestions for inbuilt commands: https://lore.kernel.org/lkml/20231208000515.1693746-2-irogers@google.com/ Thanks, Ian
Em Tue, Jan 02, 2024 at 11:30:39AM -0800, Ian Rogers escreveu: > On Thu, Dec 7, 2023 at 4:05 PM Ian Rogers <irogers@google.com> wrote: > > > > uniq will write one command name over another causing the overwritten > > string to be leaked. Fix by doing a pass that removes duplicates and a > > second that removes the holes. > > > > Signed-off-by: Ian Rogers <irogers@google.com> > > Ping for this series, no comments since sent. I applied the first one, the fix for uniq(), but somehow the second didn't work for me as in your examples, nor the third, the output is the same as before. - Arnaldo > Thanks, > Ian > > > --- > > tools/lib/subcmd/help.c | 18 ++++++++++++++---- > > 1 file changed, 14 insertions(+), 4 deletions(-) > > > > diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c > > index adfbae27dc36..8561b0f01a24 100644 > > --- a/tools/lib/subcmd/help.c > > +++ b/tools/lib/subcmd/help.c > > @@ -52,11 +52,21 @@ void uniq(struct cmdnames *cmds) > > if (!cmds->cnt) > > return; > > > > - for (i = j = 1; i < cmds->cnt; i++) > > - if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) > > - cmds->names[j++] = cmds->names[i]; > > - > > + for (i = 1; i < cmds->cnt; i++) { > > + if (!strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) > > + zfree(&cmds->names[i - 1]); > > + } > > + for (i = 0, j = 0; i < cmds->cnt; i++) { > > + if (cmds->names[i]) { > > + if (i == j) > > + j++; > > + else > > + cmds->names[j++] = cmds->names[i]; > > + } > > + } > > cmds->cnt = j; > > + while (j < i) > > + cmds->names[j++] = NULL; > > } > > > > void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes) > > -- > > 2.43.0.472.g3155946c3a-goog > > >
On Thu, Jan 4, 2024 at 1:03 PM Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > Em Tue, Jan 02, 2024 at 11:30:39AM -0800, Ian Rogers escreveu: > > On Thu, Dec 7, 2023 at 4:05 PM Ian Rogers <irogers@google.com> wrote: > > > > > > uniq will write one command name over another causing the overwritten > > > string to be leaked. Fix by doing a pass that removes duplicates and a > > > second that removes the holes. > > > > > > Signed-off-by: Ian Rogers <irogers@google.com> > > > > Ping for this series, no comments since sent. > > I applied the first one, the fix for uniq(), but somehow the second > didn't work for me as in your examples, nor the third, the output is the > same as before. I tried to repro the failure with a rebase but couldn't. I suspected libsubcmd wasn't being rebuilt or something like that. I suspect now that you have ~/.perfconfig with help.autocorrect set, which means the output will vary as it will automatically try to run the autocorrected command. Could you check for me? Thanks, Ian
Em Thu, Jan 04, 2024 at 03:29:34PM -0800, Ian Rogers escreveu: > On Thu, Jan 4, 2024 at 1:03 PM Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > Em Tue, Jan 02, 2024 at 11:30:39AM -0800, Ian Rogers escreveu: > > > On Thu, Dec 7, 2023 at 4:05 PM Ian Rogers <irogers@google.com> wrote: > > > > uniq will write one command name over another causing the overwritten > > > > string to be leaked. Fix by doing a pass that removes duplicates and a > > > > second that removes the holes. > > I applied the first one, the fix for uniq(), but somehow the second > > didn't work for me as in your examples, nor the third, the output is the > > same as before. > I tried to repro the failure with a rebase but couldn't. I suspected > libsubcmd wasn't being rebuilt or something like that. I suspect now > that you have ~/.perfconfig with help.autocorrect set, which means the > output will vary as it will automatically try to run the autocorrected > command. Could you check for me? [acme@quaco perf-tools-next]$ perf reccord Failed to run command 'reccord': No such file or directory [acme@quaco perf-tools-next]$ perf -v perf version 6.7.rc6.gcd1e3ef8bfe8 [acme@quaco perf-tools-next]$ git log --oneline -5 cd1e3ef8bfe8f827 (HEAD -> perf-tools-next) perf help: Lower levenshtein penality for deleting character c5c7365af812728e perf: Suggest inbuilt commands for unknown command b6d8b858dbbbd832 (perf-tools-next.korg/tmp.perf-tools-next, perf-tools-next.korg/perf-tools-next, number/perf-tools-next, five/perf-tools-next, acme.korg/tmp.perf-tools-next, acme.korg/perf-tools-next) perf test: test case 'Setup struct perf_event_attr' fails on s390 on z/vm 1e24ce402c97dc3c (perf-tools-next/tmp.perf-tools-next, acme/tmp.perf-tools-next) perf db-export: Fix missing reference count get in call_path_from_sample() bb177a85e82b37d3 perf tests: Add perf script test [acme@quaco perf-tools-next]$ perf reccord Failed to run command 'reccord': No such file or directory [acme@quaco perf-tools-next]$ cat ~/.perfconfig [acme@quaco perf-tools-next]$ sudo cat /etc/perfconfig [sudo] password for acme: cat: /etc/perfconfig: No such file or directory [acme@quaco perf-tools-next]$ [acme@quaco perf-tools-next]$ [acme@quaco perf-tools-next]$ sudo su - [root@quaco ~]# perf -v perf version 6.7.rc6.gcd1e3ef8bfe8 [root@quaco ~]# perf reccord Failed to run command 'reccord': No such file or directory [root@quaco ~]# cat ~/.perfconfig [root@quaco ~]# perf trace -e open*,access* perf reccord 0.000 ( 0.006 ms): perf/10791 access(filename: "/etc/ld.so.preload", mode: R) = -1 ENOENT (No such file or directory) 0.012 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC) = 3 0.035 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libunwind-x86_64.so.8", flags: RDONLY|CLOEXEC) = 3 0.084 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libunwind.so.8", flags: RDONLY|CLOEXEC) = 3 0.128 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/liblzma.so.5", flags: RDONLY|CLOEXEC) = 3 0.170 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libm.so.6", flags: RDONLY|CLOEXEC) = 3 0.221 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libopencsd_c_api.so.1", flags: RDONLY|CLOEXEC) = 3 0.264 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libz.so.1", flags: RDONLY|CLOEXEC) = 3 0.305 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libelf.so.1", flags: RDONLY|CLOEXEC) = 3 0.348 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libdebuginfod.so.1", flags: RDONLY|CLOEXEC) = 3 0.386 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libdw.so.1", flags: RDONLY|CLOEXEC) = 3 0.428 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcrypto.so.3", flags: RDONLY|CLOEXEC) = 3 0.480 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libslang.so.2", flags: RDONLY|CLOEXEC) = 3 0.526 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libperl.so.5.36", flags: RDONLY|CLOEXEC) = 3 0.575 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libc.so.6", flags: RDONLY|CLOEXEC) = 3 0.628 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpython3.11.so.1.0", flags: RDONLY|CLOEXEC) = 3 0.675 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libstdc++.so.6", flags: RDONLY|CLOEXEC) = 3 0.729 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libzstd.so.1", flags: RDONLY|CLOEXEC) = 3 0.772 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcap.so.2", flags: RDONLY|CLOEXEC) = 3 0.811 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libnuma.so.1", flags: RDONLY|CLOEXEC) = 3 0.849 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbabeltrace-ctf.so.1", flags: RDONLY|CLOEXEC) = 3 0.895 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpfm.so.4", flags: RDONLY|CLOEXEC) = 3 0.940 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libtraceevent.so.1", flags: RDONLY|CLOEXEC) = 3 0.976 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libgcc_s.so.1", flags: RDONLY|CLOEXEC) = 3 1.023 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libopencsd.so.1", flags: RDONLY|CLOEXEC) = 3 1.071 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcurl.so.4", flags: RDONLY|CLOEXEC) = 3 1.116 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbz2.so.1", flags: RDONLY|CLOEXEC) = 3 1.157 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcrypt.so.2", flags: RDONLY|CLOEXEC) = 3 1.216 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbabeltrace.so.1", flags: RDONLY|CLOEXEC) = 3 1.260 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpopt.so.0", flags: RDONLY|CLOEXEC) = 3 1.299 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libuuid.so.1", flags: RDONLY|CLOEXEC) = 3 1.341 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libgmodule-2.0.so.0", flags: RDONLY|CLOEXEC) = 3 1.382 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libglib-2.0.so.0", flags: RDONLY|CLOEXEC) = 3 1.438 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libnghttp2.so.14", flags: RDONLY|CLOEXEC) = 3 1.478 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libidn2.so.0", flags: RDONLY|CLOEXEC) = 3 1.525 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libssh.so.4", flags: RDONLY|CLOEXEC) = 3 1.576 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpsl.so.5", flags: RDONLY|CLOEXEC) = 3 1.621 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libssl.so.3", flags: RDONLY|CLOEXEC) = 3 1.663 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libgssapi_krb5.so.2", flags: RDONLY|CLOEXEC) = 3 1.707 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libldap.so.2", flags: RDONLY|CLOEXEC) = 3 1.755 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/liblber.so.2", flags: RDONLY|CLOEXEC) = 3 1.795 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbrotlidec.so.1", flags: RDONLY|CLOEXEC) = 3 1.852 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpcre2-8.so.0", flags: RDONLY|CLOEXEC) = 3 1.899 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libunistring.so.2", flags: RDONLY|CLOEXEC) = 3 1.948 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libkrb5.so.3", flags: RDONLY|CLOEXEC) = 3 1.997 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libk5crypto.so.3", flags: RDONLY|CLOEXEC) = 3 2.040 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcom_err.so.2", flags: RDONLY|CLOEXEC) = 3 2.089 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libkrb5support.so.0", flags: RDONLY|CLOEXEC) = 3 2.132 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libkeyutils.so.1", flags: RDONLY|CLOEXEC) = 3 2.175 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libresolv.so.2", flags: RDONLY|CLOEXEC) = 3 2.237 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libevent-2.1.so.7", flags: RDONLY|CLOEXEC) = 3 2.288 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libsasl2.so.3", flags: RDONLY|CLOEXEC) = 3 2.337 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbrotlicommon.so.1", flags: RDONLY|CLOEXEC) = 3 2.399 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libselinux.so.1", flags: RDONLY|CLOEXEC) = 3 9.457 ( 0.006 ms): perf/10791 access(filename: "/etc/selinux/config") = 0 9.719 ( 0.014 ms): perf/10791 openat(dfd: CWD, filename: "/proc/self/status") = 3 9.759 ( 0.007 ms): perf/10791 openat(dfd: CWD, filename: "/sys/devices/system/node", flags: RDONLY|CLOEXEC|DIRECTORY|NONBLOCK) = 3 9.786 ( 0.006 ms): perf/10791 openat(dfd: CWD, filename: "/sys/devices/system/node/node0/meminfo") = 4 9.825 ( 0.006 ms): perf/10791 openat(dfd: CWD, filename: "/sys/devices/system/cpu/possible", flags: RDONLY|CLOEXEC) = 3 9.837 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/proc/self/status") = 3 9.962 ( 0.005 ms): perf/10791 access(filename: "/home/acme/etc/perfconfig", mode: R) = -1 ENOENT (No such file or directory) Failed to run command 'reccord': No such file or directory [root@quaco ~]# [root@quaco ~]# perf -vv perf version 6.7.rc6.gcd1e3ef8bfe8 dwarf: [ on ] # HAVE_DWARF_SUPPORT dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT libbfd: [ OFF ] # HAVE_LIBBFD_SUPPORT debuginfod: [ on ] # HAVE_DEBUGINFOD_SUPPORT libelf: [ on ] # HAVE_LIBELF_SUPPORT libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT libperl: [ on ] # HAVE_LIBPERL_SUPPORT libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT libslang: [ on ] # HAVE_SLANG_SUPPORT libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT zlib: [ on ] # HAVE_ZLIB_SUPPORT lzma: [ on ] # HAVE_LZMA_SUPPORT get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT bpf: [ on ] # HAVE_LIBBPF_SUPPORT aio: [ on ] # HAVE_AIO_SUPPORT zstd: [ on ] # HAVE_ZSTD_SUPPORT libpfm4: [ on ] # HAVE_LIBPFM libtraceevent: [ on ] # HAVE_LIBTRACEEVENT bpf_skeletons: [ on ] # HAVE_BPF_SKEL [root@quaco ~]#
On Fri, Jan 5, 2024 at 6:54 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > Em Thu, Jan 04, 2024 at 03:29:34PM -0800, Ian Rogers escreveu: > > On Thu, Jan 4, 2024 at 1:03 PM Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > > Em Tue, Jan 02, 2024 at 11:30:39AM -0800, Ian Rogers escreveu: > > > > On Thu, Dec 7, 2023 at 4:05 PM Ian Rogers <irogers@google.com> wrote: > > > > > uniq will write one command name over another causing the overwritten > > > > > string to be leaked. Fix by doing a pass that removes duplicates and a > > > > > second that removes the holes. > > > > I applied the first one, the fix for uniq(), but somehow the second > > > didn't work for me as in your examples, nor the third, the output is the > > > same as before. > > > I tried to repro the failure with a rebase but couldn't. I suspected > > libsubcmd wasn't being rebuilt or something like that. I suspect now > > that you have ~/.perfconfig with help.autocorrect set, which means the > > output will vary as it will automatically try to run the autocorrected > > command. Could you check for me? > > [acme@quaco perf-tools-next]$ perf reccord > Failed to run command 'reccord': No such file or directory > [acme@quaco perf-tools-next]$ perf -v > perf version 6.7.rc6.gcd1e3ef8bfe8 > [acme@quaco perf-tools-next]$ git log --oneline -5 > cd1e3ef8bfe8f827 (HEAD -> perf-tools-next) perf help: Lower levenshtein penality for deleting character > c5c7365af812728e perf: Suggest inbuilt commands for unknown command > b6d8b858dbbbd832 (perf-tools-next.korg/tmp.perf-tools-next, perf-tools-next.korg/perf-tools-next, number/perf-tools-next, five/perf-tools-next, acme.korg/tmp.perf-tools-next, acme.korg/perf-tools-next) perf test: test case 'Setup struct perf_event_attr' fails on s390 on z/vm > 1e24ce402c97dc3c (perf-tools-next/tmp.perf-tools-next, acme/tmp.perf-tools-next) perf db-export: Fix missing reference count get in call_path_from_sample() > bb177a85e82b37d3 perf tests: Add perf script test > [acme@quaco perf-tools-next]$ perf reccord > Failed to run command 'reccord': No such file or directory > [acme@quaco perf-tools-next]$ cat ~/.perfconfig > [acme@quaco perf-tools-next]$ sudo cat /etc/perfconfig > [sudo] password for acme: > cat: /etc/perfconfig: No such file or directory > [acme@quaco perf-tools-next]$ > [acme@quaco perf-tools-next]$ > [acme@quaco perf-tools-next]$ sudo su - > [root@quaco ~]# perf -v > perf version 6.7.rc6.gcd1e3ef8bfe8 > [root@quaco ~]# perf reccord > Failed to run command 'reccord': No such file or directory > [root@quaco ~]# cat ~/.perfconfig > [root@quaco ~]# perf trace -e open*,access* perf reccord > 0.000 ( 0.006 ms): perf/10791 access(filename: "/etc/ld.so.preload", mode: R) = -1 ENOENT (No such file or directory) > 0.012 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC) = 3 > 0.035 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libunwind-x86_64.so.8", flags: RDONLY|CLOEXEC) = 3 > 0.084 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libunwind.so.8", flags: RDONLY|CLOEXEC) = 3 > 0.128 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/liblzma.so.5", flags: RDONLY|CLOEXEC) = 3 > 0.170 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libm.so.6", flags: RDONLY|CLOEXEC) = 3 > 0.221 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libopencsd_c_api.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.264 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libz.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.305 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libelf.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.348 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libdebuginfod.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.386 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libdw.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.428 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcrypto.so.3", flags: RDONLY|CLOEXEC) = 3 > 0.480 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libslang.so.2", flags: RDONLY|CLOEXEC) = 3 > 0.526 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libperl.so.5.36", flags: RDONLY|CLOEXEC) = 3 > 0.575 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libc.so.6", flags: RDONLY|CLOEXEC) = 3 > 0.628 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpython3.11.so.1.0", flags: RDONLY|CLOEXEC) = 3 > 0.675 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libstdc++.so.6", flags: RDONLY|CLOEXEC) = 3 > 0.729 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libzstd.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.772 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcap.so.2", flags: RDONLY|CLOEXEC) = 3 > 0.811 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libnuma.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.849 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbabeltrace-ctf.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.895 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpfm.so.4", flags: RDONLY|CLOEXEC) = 3 > 0.940 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libtraceevent.so.1", flags: RDONLY|CLOEXEC) = 3 > 0.976 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libgcc_s.so.1", flags: RDONLY|CLOEXEC) = 3 > 1.023 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libopencsd.so.1", flags: RDONLY|CLOEXEC) = 3 > 1.071 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcurl.so.4", flags: RDONLY|CLOEXEC) = 3 > 1.116 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbz2.so.1", flags: RDONLY|CLOEXEC) = 3 > 1.157 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcrypt.so.2", flags: RDONLY|CLOEXEC) = 3 > 1.216 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbabeltrace.so.1", flags: RDONLY|CLOEXEC) = 3 > 1.260 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpopt.so.0", flags: RDONLY|CLOEXEC) = 3 > 1.299 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libuuid.so.1", flags: RDONLY|CLOEXEC) = 3 > 1.341 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libgmodule-2.0.so.0", flags: RDONLY|CLOEXEC) = 3 > 1.382 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libglib-2.0.so.0", flags: RDONLY|CLOEXEC) = 3 > 1.438 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libnghttp2.so.14", flags: RDONLY|CLOEXEC) = 3 > 1.478 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libidn2.so.0", flags: RDONLY|CLOEXEC) = 3 > 1.525 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libssh.so.4", flags: RDONLY|CLOEXEC) = 3 > 1.576 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpsl.so.5", flags: RDONLY|CLOEXEC) = 3 > 1.621 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libssl.so.3", flags: RDONLY|CLOEXEC) = 3 > 1.663 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libgssapi_krb5.so.2", flags: RDONLY|CLOEXEC) = 3 > 1.707 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libldap.so.2", flags: RDONLY|CLOEXEC) = 3 > 1.755 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/liblber.so.2", flags: RDONLY|CLOEXEC) = 3 > 1.795 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbrotlidec.so.1", flags: RDONLY|CLOEXEC) = 3 > 1.852 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libpcre2-8.so.0", flags: RDONLY|CLOEXEC) = 3 > 1.899 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libunistring.so.2", flags: RDONLY|CLOEXEC) = 3 > 1.948 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libkrb5.so.3", flags: RDONLY|CLOEXEC) = 3 > 1.997 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libk5crypto.so.3", flags: RDONLY|CLOEXEC) = 3 > 2.040 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libcom_err.so.2", flags: RDONLY|CLOEXEC) = 3 > 2.089 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libkrb5support.so.0", flags: RDONLY|CLOEXEC) = 3 > 2.132 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libkeyutils.so.1", flags: RDONLY|CLOEXEC) = 3 > 2.175 ( 0.004 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libresolv.so.2", flags: RDONLY|CLOEXEC) = 3 > 2.237 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libevent-2.1.so.7", flags: RDONLY|CLOEXEC) = 3 > 2.288 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libsasl2.so.3", flags: RDONLY|CLOEXEC) = 3 > 2.337 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libbrotlicommon.so.1", flags: RDONLY|CLOEXEC) = 3 > 2.399 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/lib64/libselinux.so.1", flags: RDONLY|CLOEXEC) = 3 > 9.457 ( 0.006 ms): perf/10791 access(filename: "/etc/selinux/config") = 0 > 9.719 ( 0.014 ms): perf/10791 openat(dfd: CWD, filename: "/proc/self/status") = 3 > 9.759 ( 0.007 ms): perf/10791 openat(dfd: CWD, filename: "/sys/devices/system/node", flags: RDONLY|CLOEXEC|DIRECTORY|NONBLOCK) = 3 > 9.786 ( 0.006 ms): perf/10791 openat(dfd: CWD, filename: "/sys/devices/system/node/node0/meminfo") = 4 > 9.825 ( 0.006 ms): perf/10791 openat(dfd: CWD, filename: "/sys/devices/system/cpu/possible", flags: RDONLY|CLOEXEC) = 3 > 9.837 ( 0.005 ms): perf/10791 openat(dfd: CWD, filename: "/proc/self/status") = 3 > 9.962 ( 0.005 ms): perf/10791 access(filename: "/home/acme/etc/perfconfig", mode: R) = -1 ENOENT (No such file or directory) > Failed to run command 'reccord': No such file or directory > [root@quaco ~]# > [root@quaco ~]# perf -vv > perf version 6.7.rc6.gcd1e3ef8bfe8 > dwarf: [ on ] # HAVE_DWARF_SUPPORT > dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT > syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT > libbfd: [ OFF ] # HAVE_LIBBFD_SUPPORT > debuginfod: [ on ] # HAVE_DEBUGINFOD_SUPPORT > libelf: [ on ] # HAVE_LIBELF_SUPPORT > libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT > numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT > libperl: [ on ] # HAVE_LIBPERL_SUPPORT > libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT > libslang: [ on ] # HAVE_SLANG_SUPPORT > libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT > libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT > libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT > zlib: [ on ] # HAVE_ZLIB_SUPPORT > lzma: [ on ] # HAVE_LZMA_SUPPORT > get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT > bpf: [ on ] # HAVE_LIBBPF_SUPPORT > aio: [ on ] # HAVE_AIO_SUPPORT > zstd: [ on ] # HAVE_ZSTD_SUPPORT > libpfm4: [ on ] # HAVE_LIBPFM > libtraceevent: [ on ] # HAVE_LIBTRACEEVENT > bpf_skeletons: [ on ] # HAVE_BPF_SKEL > [root@quaco ~]# Thanks Arnaldo, I tried b4 am-ing the patches and repro-ing in a clean tree. I'm still not able to do it. Knowing what is going on in help_unknown_cmd in tools/perf/util/help-unknown-cmd.c would shed some light on the matter. I'll see if I can get other ideas. Thanks, Ian
diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c index adfbae27dc36..8561b0f01a24 100644 --- a/tools/lib/subcmd/help.c +++ b/tools/lib/subcmd/help.c @@ -52,11 +52,21 @@ void uniq(struct cmdnames *cmds) if (!cmds->cnt) return; - for (i = j = 1; i < cmds->cnt; i++) - if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) - cmds->names[j++] = cmds->names[i]; - + for (i = 1; i < cmds->cnt; i++) { + if (!strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) + zfree(&cmds->names[i - 1]); + } + for (i = 0, j = 0; i < cmds->cnt; i++) { + if (cmds->names[i]) { + if (i == j) + j++; + else + cmds->names[j++] = cmds->names[i]; + } + } cmds->cnt = j; + while (j < i) + cmds->names[j++] = NULL; } void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)