mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Clark <james.clark@arm.com>
To: Ameer Hamza <amhamza.mgc@gmail.com>
Cc: German Gomez <german.gomez@arm.com>,
	peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	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: Tue, 25 Jan 2022 09:35:49 +0000	[thread overview]
Message-ID: <8983b963-2139-ecb3-3a31-b5e225db389c@arm.com> (raw)
In-Reply-To: <20220124202907.GA5741@hamza-OptiPlex-7040>



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>

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

  reply	other threads:[~2022-01-25  9:40 UTC|newest]

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

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=8983b963-2139-ecb3-3a31-b5e225db389c@arm.com \
    --to=james.clark@arm.com \
    --cc=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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®