Skip to contentSkip to conversation

check null of sym pointer before using it

Perf bug-fix Shan Wei 3 participants 4 messages Jun 5, 2012 – Jun 20, 2012 perf events

lore
Share & tools
lore

Shan Wei

author
#0 lore raw

From: Samuel Liao <[email protected]>

Sometimes, sym will be null that causing perf crash.

---
 tools/perf/ui/browsers/annotate.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
tools/perf/ui/browsers/annotate.c +3 -1
index 4deea6a..50873a8 100644
@@ -814,7 +814,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 {
 	struct disasm_line *pos, *n;
 	struct annotation *notes;
-	const size_t size = symbol__size(sym);
+	size_t size;
 	struct map_symbol ms = {
 		.map = map,
 		.sym = sym,
@@ -834,6 +834,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 	if (sym == NULL)
 		return -1;
 
+	size = symbol__size(sym);
+
 	if (map->dso->annotate_warned)
 		return -1;
 
Signature · 1 line
1.7.1
author
#1 lore raw

ping.....

It's a obvious function bug.....

Shan Wei said, at 2012/6/5 13:14:

Quoted 31 lines

From: Samuel Liao <[email protected]>

Sometimes, sym will be null that causing perf crash.

---
 tools/perf/ui/browsers/annotate.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
tools/perf/ui/browsers/annotate.c +3 -1
index 4deea6a..50873a8 100644
@@ -814,7 +814,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 {
 	struct disasm_line *pos, *n;
 	struct annotation *notes;
-	const size_t size = symbol__size(sym);
+	size_t size;
 	struct map_symbol ms = {
 		.map = map,
 		.sym = sym,
@@ -834,6 +834,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 	if (sym == NULL)
 		return -1;
 
+	size = symbol__size(sym);
+
 	if (map->dso->annotate_warned)
 		return -1;
 
maintainer Reviewed-by
#2 lore raw

Hi,

Quoted 11 lines · Shan Wei

ping.....

It's a obvious function bug.....

Shan Wei said, at 2012/6/5 13:14:

Quoted 5 lines

From: Samuel Liao <[email protected]>

Sometimes, sym will be null that causing perf crash.

Thanks for the fix.
Namhyung

Quoted 26 lines
Quoted 26 lines
---
 tools/perf/ui/browsers/annotate.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
tools/perf/ui/browsers/annotate.c +3 -1
index 4deea6a..50873a8 100644
@@ -814,7 +814,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 {
 	struct disasm_line *pos, *n;
 	struct annotation *notes;
-	const size_t size = symbol__size(sym);
+	size_t size;
 	struct map_symbol ms = {
 		.map = map,
 		.sym = sym,
@@ -834,6 +834,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 	if (sym == NULL)
 		return -1;
 
+	size = symbol__size(sym);
+
 	if (map->dso->annotate_warned)
 		return -1;
 
#3 lore raw

[tip:perf/core] perf annotate: Check null of sym pointer before using it

In reply to Shan Wei
Commit-ID:  c0a58fb2bdf033df433cad9009c7dac4c6b872b0
Gitweb:     http://git.kernel.org/tip/c0a58fb2bdf033df433cad9009c7dac4c6b872b0
Author:     Samuel Liao <[email protected]>
AuthorDate: Tue, 5 Jun 2012 13:14:59 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 19 Jun 2012 14:30:26 -0300

perf annotate: Check null of sym pointer before using it

Sym may be NULL, and that will cause perf to crash.

---
 tools/perf/ui/browsers/annotate.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
tools/perf/ui/browsers/annotate.c +3 -1
index 34b1c46..67a2703 100644
@@ -814,7 +814,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 {
 	struct disasm_line *pos, *n;
 	struct annotation *notes;
-	const size_t size = symbol__size(sym);
+	size_t size;
 	struct map_symbol ms = {
 		.map = map,
 		.sym = sym,
@@ -834,6 +834,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 	if (sym == NULL)
 		return -1;
 
+	size = symbol__size(sym);
+
 	if (map->dso->annotate_warned)
 		return -1;