Skip to content

Commit 2a3d252

Browse files
captain5050acmel
authored andcommitted
perf parse-events: Add defensive NULL check
Terms may have a NULL config in which case a strcmp will SEGV. This can be reproduced with: perf stat -e '*/event=?,nr/' sleep 1 Add a NULL check to avoid this. This was caught by LLVM's libfuzzer. Signed-off-by: Ian Rogers <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jin Yao <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent eadcaa3 commit 2a3d252

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

tools/perf/util/pmu.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -984,12 +984,11 @@ static int pmu_resolve_param_term(struct parse_events_term *term,
984984
struct parse_events_term *t;
985985

986986
list_for_each_entry(t, head_terms, list) {
987-
if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
988-
if (!strcmp(t->config, term->config)) {
989-
t->used = true;
990-
*value = t->val.num;
991-
return 0;
992-
}
987+
if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM &&
988+
t->config && !strcmp(t->config, term->config)) {
989+
t->used = true;
990+
*value = t->val.num;
991+
return 0;
993992
}
994993
}
995994

0 commit comments

Comments
 (0)