* [PATCH] [perf] sort : Fix null pointer dereference in _hist_entry__sym_snprintf
@ 2020-06-18 0:30 Gaurav Singh
2020-06-18 14:13 ` Andi Kleen
0 siblings, 1 reply; 2+ messages in thread
From: Gaurav Singh @ 2020-06-18 0:30 UTC (permalink / raw)
To: gaurav1086, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ravi Bangoria, Andi Kleen, open list:PERFORMANCE EVENTS SUBSYSTEM
The pointer ms can be NULL. Add null check before
dereferencing it to avoid segmentation fault.
Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
tools/perf/util/sort.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index d42339df20f8..25c7c96893f6 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -294,6 +294,9 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
u64 ip, char level, char *bf, size_t size,
unsigned int width)
{
+ if (!ms)
+ return 0;
+
struct symbol *sym = ms->sym;
struct map *map = ms->map;
size_t ret = 0;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] [perf] sort : Fix null pointer dereference in _hist_entry__sym_snprintf
2020-06-18 0:30 [PATCH] [perf] sort : Fix null pointer dereference in _hist_entry__sym_snprintf Gaurav Singh
@ 2020-06-18 14:13 ` Andi Kleen
0 siblings, 0 replies; 2+ messages in thread
From: Andi Kleen @ 2020-06-18 14:13 UTC (permalink / raw)
To: Gaurav Singh
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ravi Bangoria, open list:PERFORMANCE EVENTS SUBSYSTEM
> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index d42339df20f8..25c7c96893f6 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
> @@ -294,6 +294,9 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
> u64 ip, char level, char *bf, size_t size,
> unsigned int width)
> {
> + if (!ms)
> + return 0;
> +
> struct symbol *sym = ms->sym;
> struct map *map = ms->map;
> size_t ret = 0;
This should have given warnings because Linux and perf coding style
forbids fixed statement/declarations.
Also what's the backtrace where it is NULL? Perhaps better to fix it in
the caller.
-Andi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-18 14:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-18 0:30 [PATCH] [perf] sort : Fix null pointer dereference in _hist_entry__sym_snprintf Gaurav Singh
2020-06-18 14:13 ` Andi Kleen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox