linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Chenyuan Mi <cymi20@fudan.edu.cn>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1 1/3] lib subcmd: Fix memory leak in uniq
Date: Thu, 4 Jan 2024 18:03:11 -0300	[thread overview]
Message-ID: <ZZcdDyyADG8dP8LM@kernel.org> (raw)
In-Reply-To: <CAP-5=fVQfqS6gu9Ua3Exijc_ZaBzrt2=1PMopgdoyC_6R_cnaQ@mail.gmail.com>

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
> >
> 

-- 

- Arnaldo

  parent reply	other threads:[~2024-01-04 21:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-08  0:05 [PATCH v1 1/3] lib subcmd: Fix memory leak in uniq Ian Rogers
2023-12-08  0:05 ` [PATCH v1 2/3] perf: Suggest inbuilt commands for unknown command Ian Rogers
2023-12-08  0:05 ` [PATCH v1 3/3] perf help: Lower levenshtein penality for deleting character Ian Rogers
2024-01-02 19:30 ` [PATCH v1 1/3] lib subcmd: Fix memory leak in uniq Ian Rogers
2024-01-04 17:56   ` Ian Rogers
2024-01-04 21:03   ` Arnaldo Carvalho de Melo [this message]
2024-01-04 23:29     ` Ian Rogers
2024-01-05 14:53       ` Arnaldo Carvalho de Melo
2024-01-06  5:44         ` Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZZcdDyyADG8dP8LM@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=cymi20@fudan.edu.cn \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).