Skip to contentSkip to conversation

sort : Fix null pointer dereference in _hist_entry__sym_snprintf

PATCH In review Gaurav Singh 2 participants 2 messages Jun 18, 2020 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sort : Fix null pointer dereference in _hist_entry__sym_snprintf

The pointer ms can be NULL. Add null check before
dereferencing it to avoid segmentation fault.

---
 tools/perf/util/sort.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/sort.c +3 -0
index d42339df20f8..25c7c96893f6 100644
@@ -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;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines
tools/perf/util/sort.c +0 -0
index d42339df20f8..25c7c96893f6 100644

tools/perf/util/sort.c static int _hist_entry__sym_snprintf(struct map_symbol *ms, · line 302

Quoted 9 lines
tools/perf/util/sort.c +3 -0
@@ -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