diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2012-04-23 00:58:38 -0400 |
---|---|---|
committer | Namhyung Kim <namhyung@kernel.org> | 2012-07-04 00:40:31 -0400 |
commit | 0fed48341529716c38493be66591bda458921b75 (patch) | |
tree | 9064bbcee7545d37682d0c93436c08bb0382ee58 /tools | |
parent | e54b34aed1c4082ed03f4d1f7a19276059b1e30a (diff) |
tools lib traceevent: Check return value of arg_to_str()
The arg_to_str() can fail so we should handle that case properly.
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1335157118-14658-12-git-send-email-namhyung.kim@lge.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lib/traceevent/parse-filter.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c index d54c2b4dbd9f..f020ac61f9c1 100644 --- a/tools/lib/traceevent/parse-filter.c +++ b/tools/lib/traceevent/parse-filter.c | |||
@@ -2026,11 +2026,13 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2026 | char *lstr; | 2026 | char *lstr; |
2027 | char *rstr; | 2027 | char *rstr; |
2028 | char *op; | 2028 | char *op; |
2029 | char *str; | 2029 | char *str = NULL; |
2030 | int len; | 2030 | int len; |
2031 | 2031 | ||
2032 | lstr = arg_to_str(filter, arg->exp.left); | 2032 | lstr = arg_to_str(filter, arg->exp.left); |
2033 | rstr = arg_to_str(filter, arg->exp.right); | 2033 | rstr = arg_to_str(filter, arg->exp.right); |
2034 | if (!lstr || !rstr) | ||
2035 | goto out; | ||
2034 | 2036 | ||
2035 | switch (arg->exp.type) { | 2037 | switch (arg->exp.type) { |
2036 | case FILTER_EXP_ADD: | 2038 | case FILTER_EXP_ADD: |
@@ -2070,6 +2072,7 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2070 | len = strlen(op) + strlen(lstr) + strlen(rstr) + 4; | 2072 | len = strlen(op) + strlen(lstr) + strlen(rstr) + 4; |
2071 | str = malloc_or_die(len); | 2073 | str = malloc_or_die(len); |
2072 | snprintf(str, len, "%s %s %s", lstr, op, rstr); | 2074 | snprintf(str, len, "%s %s %s", lstr, op, rstr); |
2075 | out: | ||
2073 | free(lstr); | 2076 | free(lstr); |
2074 | free(rstr); | 2077 | free(rstr); |
2075 | 2078 | ||
@@ -2086,6 +2089,8 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2086 | 2089 | ||
2087 | lstr = arg_to_str(filter, arg->num.left); | 2090 | lstr = arg_to_str(filter, arg->num.left); |
2088 | rstr = arg_to_str(filter, arg->num.right); | 2091 | rstr = arg_to_str(filter, arg->num.right); |
2092 | if (!lstr || !rstr) | ||
2093 | goto out; | ||
2089 | 2094 | ||
2090 | switch (arg->num.type) { | 2095 | switch (arg->num.type) { |
2091 | case FILTER_CMP_EQ: | 2096 | case FILTER_CMP_EQ: |
@@ -2122,6 +2127,7 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2122 | break; | 2127 | break; |
2123 | } | 2128 | } |
2124 | 2129 | ||
2130 | out: | ||
2125 | free(lstr); | 2131 | free(lstr); |
2126 | free(rstr); | 2132 | free(rstr); |
2127 | return str; | 2133 | return str; |
@@ -2272,7 +2278,12 @@ int pevent_filter_compare(struct event_filter *filter1, struct event_filter *fil | |||
2272 | /* The best way to compare complex filters is with strings */ | 2278 | /* The best way to compare complex filters is with strings */ |
2273 | str1 = arg_to_str(filter1, filter_type1->filter); | 2279 | str1 = arg_to_str(filter1, filter_type1->filter); |
2274 | str2 = arg_to_str(filter2, filter_type2->filter); | 2280 | str2 = arg_to_str(filter2, filter_type2->filter); |
2275 | result = strcmp(str1, str2) != 0; | 2281 | if (str1 && str2) |
2282 | result = strcmp(str1, str2) != 0; | ||
2283 | else | ||
2284 | /* bail out if allocation fails */ | ||
2285 | result = 1; | ||
2286 | |||
2276 | free(str1); | 2287 | free(str1); |
2277 | free(str2); | 2288 | free(str2); |
2278 | if (result) | 2289 | if (result) |