perf events parse: Use just one parse events state struct
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 Aug 2017 17:22:50 +0000 (14:22 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 Aug 2017 19:39:15 +0000 (16:39 -0300)
Andi reported problems when parse errors were detected with vendor
events (json), because in the yyparse/parse_events_parse function we
dereferenced the _data parameter to two different structs, with
different layouts, which ended up making parse_events_evlist->error to
point to random stack addresses.

Fix it by making _data to always be struct parse_events_state, changing
the only place where 'struct parse_events_term' was used in
parse_events.y.

Reported-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-bc27lshz823hxl8n9nkelcgh@git.kernel.org
Fixes: 90e2b22dee90 ("perf/tool: Add support to reuse event grammar to parse out terms")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h
tools/perf/util/parse-events.y

index 272eab7f5ac8cf4c3d36132022d388b4f055a31a..d4fcf048aa9ec618f4395d53c93181f60df2d9dc 100644 (file)
@@ -1656,7 +1656,7 @@ static int parse_events__scanner(const char *str, void *data, int start_token)
  */
 int parse_events_terms(struct list_head *terms, const char *str)
 {
-       struct parse_events_terms data = {
+       struct parse_events_state data = {
                .terms = NULL,
        };
        int ret;
index 8fff8423469b04f390c60a3ea39b253319cc824d..2a36179378940b9b18131e19d18d8e9e6b6a64fb 100644 (file)
@@ -114,10 +114,7 @@ struct parse_events_state {
        int                        nr_groups;
        struct parse_events_error *error;
        struct perf_evlist        *evlist;
-};
-
-struct parse_events_terms {
-       struct list_head *terms;
+       struct list_head          *terms;
 };
 
 void parse_events__shrink_config_terms(void);
index 403a221266b8a76af5dc339385590ae69e63f7aa..4b37546e491449f7aed09e9471a69b83f3621d12 100644 (file)
@@ -488,7 +488,7 @@ opt_event_config:
 
 start_terms: event_config
 {
-       struct parse_events_terms *data = _data;
+       struct parse_events_state *data = _data;
        data->terms = $1;
 }