All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: James Clark <james.clark@arm.com>
Cc: Ameer Hamza <amhamza.mgc@gmail.com>,
	German Gomez <german.gomez@arm.com>,
	peterz@infradead.org, mingo@redhat.com, rickyman7@gmail.com,
	alexey.v.bayduraev@linux.intel.com, adrian.hunter@intel.com,
	leo.yan@linaro.org, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@redhat.com,
	namhyung@kernel.org
Subject: Re: [PATCH] perf session: check for null pointer before derefernce
Date: Sun, 6 Feb 2022 08:41:28 -0300	[thread overview]
Message-ID: <Yf+z6LmCsyymABcN@kernel.org> (raw)
In-Reply-To: <8983b963-2139-ecb3-3a31-b5e225db389c@arm.com>

Em Tue, Jan 25, 2022 at 09:35:49AM +0000, James Clark escreveu:
> 
> 
> On 24/01/2022 20:29, Ameer Hamza wrote:
> > On Mon, Jan 24, 2022 at 03:30:17PM +0000, James Clark wrote:
> >>
> >>
> >> On 24/01/2022 15:00, Ameer Hamza wrote:
> >>> Move null pointer check before dereferncing the variable
> >>>
> >>> Addresses-Coverity: 1497622 ("Derereference before null check")
> >>>
> >>> Signed-off-by: Ameer Hamza <amhamza.mgc@gmail.com>
> >>> ---
> >>>  tools/perf/util/session.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> >>> index f19348dddd55..e1014ab62c10 100644
> >>> --- a/tools/perf/util/session.c
> >>> +++ b/tools/perf/util/session.c
> >>> @@ -1503,11 +1503,11 @@ static int machines__deliver_event(struct machines *machines,
> >>>  			++evlist->stats.nr_unknown_id;
> >>>  			return 0;
> >>>  		}
> >>> -		dump_sample(evsel, event, sample, perf_env__arch(machine->env));
> >>>  		if (machine == NULL) {
> >>>  			++evlist->stats.nr_unprocessable_samples;
> >>>  			return 0;
> >>>  		}
> >>> +		dump_sample(evsel, event, sample, perf_env__arch(machine->env));
> >>>  		return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine);
> >>>  	case PERF_RECORD_MMAP:
> >>>  		return tool->mmap(tool, event, sample, machine);
> >>>
> >>
> >> Hi Ameer,
> >>
> >> This mistake was made recently, but I don't think your change is the desired behavior.
> >>
> >> It should be possible to dump stuff if machine is null. null or an empty string
> >> should be passed to dump_sample(). It looks like some of the printfs still attempt to
> >> show something in this case, although I didn't check them all.
> > 
> > Hi James,
> > 
> > Thank you for your response. I understand your point.
> > 
> > Do you think following changes would be ok?
> 
> Yep looks good. With that change:
> 
> Reviewed-by: James Clark <james.clark@arm.com>

Thanks, applied.

- Arnaldo

 
> > 
> > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> > index f19348dddd55..210eeee3dd70 100644
> > --- a/tools/perf/util/session.c
> > +++ b/tools/perf/util/session.c
> > @@ -1503,11 +1503,12 @@ static int machines__deliver_event(struct machines *machines,
> >                         ++evlist->stats.nr_unknown_id;
> >                         return 0;
> >                 }
> > -               dump_sample(evsel, event, sample, perf_env__arch(machine->env));
> >                 if (machine == NULL) {
> >                         ++evlist->stats.nr_unprocessable_samples;
> > +                       dump_sample(evsel, event, sample, perf_env__arch(NULL));
> >                         return 0;
> >                 }
> > +               dump_sample(evsel, event, sample, perf_env__arch(machine->env));
> >                 return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine);
> >         case PERF_RECORD_MMAP:
> >                 return tool->mmap(tool, event, sample, machine);
> > 
> > Thanks,
> > Hamza
> > 

-- 

- Arnaldo

      parent reply	other threads:[~2022-02-06 11:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 15:00 [PATCH] perf session: check for null pointer before derefernce Ameer Hamza
2022-01-24 15:30 ` James Clark
2022-01-24 20:29   ` Ameer Hamza
2022-01-25  9:35     ` James Clark
2022-01-25 12:11       ` [PATCH v2] " Ameer Hamza
2022-02-06 11:41       ` Arnaldo Carvalho de Melo [this message]

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=Yf+z6LmCsyymABcN@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.v.bayduraev@linux.intel.com \
    --cc=amhamza.mgc@gmail.com \
    --cc=german.gomez@arm.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@redhat.com \
    --cc=leo.yan@linaro.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 \
    --cc=rickyman7@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.