Skip to contentSkip to conversation

perf stat: Potential NULL dereference in print_aggr()

PATCH In review Dan Carpenter 2 participants 2 messages Oct 13, 2018 – Oct 14, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf stat: Potential NULL dereference in print_aggr()

Smatch complains that:

    ./tools/perf/util/stat-display.c:616 print_aggr()
    error: we previously assumed 'config->aggr_map' could be null (see line 607)

Not only that, but it looks like aggr_update_shadow() can Oops if "config->aggr_get_id" is NULL. The intent seems to have been to return if either of these pointers is NULL.

---
 tools/perf/util/stat-display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/stat-display.c +1 -1
index e7b4c44ebb62..db635c01d3a3 100644
@@ -604,7 +604,7 @@ static void print_aggr(struct perf_stat_config *config,
 	u64 ena, run, val;
 	bool first;
 
-	if (!(config->aggr_map || config->aggr_get_id))
+	if (!config->aggr_map || !config->aggr_get_id)
 		return;
 
 	aggr_update_shadow(config, evlist);
Signature · 1 line
2.18.0
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Dan Carpenter

Smatch complains that:

    ./tools/perf/util/stat-display.c:616 print_aggr()
    error: we previously assumed 'config->aggr_map' could be null (see line 607)

Not only that, but it looks like aggr_update_shadow() can Oops if "config->aggr_get_id" is NULL. The intent seems to have been to return if either of these pointers is NULL.

Fixes 86ee6e18f6cb ("perf stat: Refactor aggregation code")

thanks,
jirka

Quoted 20 lines
---
 tools/perf/util/stat-display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/stat-display.c +1 -1
index e7b4c44ebb62..db635c01d3a3 100644
@@ -604,7 +604,7 @@ static void print_aggr(struct perf_stat_config *config,
 	u64 ena, run, val;
 	bool first;
 
-	if (!(config->aggr_map || config->aggr_get_id))
+	if (!config->aggr_map || !config->aggr_get_id)
 		return;
 
 	aggr_update_shadow(config, evlist);
Signature · 1 line
2.18.0