[PATCH] perf tools: avoid segv in pmu_resolve_param_term
From: Ian Rogers
Date: Mon Nov 25 2019 - 12:41:43 EST
PE_TERMS may set the config to NULL, avoid dereferencing this in
pmu_resolve_param_term. Error detected by LLVM's libFuzzer.
To reproduce the segv run:
$ perf record -e 'm/event=?,time/' ls
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/pmu.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index e8d348988026..1a6e36353407 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -988,13 +988,17 @@ static int pmu_resolve_param_term(struct parse_events_term *term,
struct parse_events_term *t;
list_for_each_entry(t, head_terms, list) {
- if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
- if (!strcmp(t->config, term->config)) {
- t->used = true;
- *value = t->val.num;
- return 0;
- }
- }
+ if (t->type_val != PARSE_EVENTS__TERM_TYPE_NUM)
+ continue;
+
+ if (t->config == NULL && term->config != NULL)
+ continue;
+ else if (strcmp(t->config, term->config))
+ continue;
+
+ t->used = true;
+ *value = t->val.num;
+ return 0;
}
if (verbose > 0)
--
2.24.0.432.g9d3f5f5b63-goog