From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Namhyung Kim <namhyung.kim@lge.com>,
Namhyung Kim <namhyung@gmail.com>,
Arnaldo Carvalho de Melo <acme@infradead.org>,
Borislav Petkov <bp@alien8.de>, David Ahern <dsahern@gmail.com>
Subject: [PATCH 14/16] tools lib traceevent: Check return value of arg_to_str()
Date: Wed, 4 Jul 2012 14:35:28 +0900 [thread overview]
Message-ID: <1341380130-23863-14-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1341380130-23863-1-git-send-email-namhyung@kernel.org>
From: Namhyung Kim <namhyung.kim@lge.com>
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>
---
tools/lib/traceevent/parse-filter.c | 15 +++++++++++++--
1 file 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)
char *lstr;
char *rstr;
char *op;
- char *str;
+ char *str = NULL;
int len;
lstr = arg_to_str(filter, arg->exp.left);
rstr = arg_to_str(filter, arg->exp.right);
+ if (!lstr || !rstr)
+ goto out;
switch (arg->exp.type) {
case FILTER_EXP_ADD:
@@ -2070,6 +2072,7 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
len = strlen(op) + strlen(lstr) + strlen(rstr) + 4;
str = malloc_or_die(len);
snprintf(str, len, "%s %s %s", lstr, op, rstr);
+out:
free(lstr);
free(rstr);
@@ -2086,6 +2089,8 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
lstr = arg_to_str(filter, arg->num.left);
rstr = arg_to_str(filter, arg->num.right);
+ if (!lstr || !rstr)
+ goto out;
switch (arg->num.type) {
case FILTER_CMP_EQ:
@@ -2122,6 +2127,7 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
break;
}
+out:
free(lstr);
free(rstr);
return str;
@@ -2272,7 +2278,12 @@ int pevent_filter_compare(struct event_filter *filter1, struct event_filter *fil
/* The best way to compare complex filters is with strings */
str1 = arg_to_str(filter1, filter_type1->filter);
str2 = arg_to_str(filter2, filter_type2->filter);
- result = strcmp(str1, str2) != 0;
+ if (str1 && str2)
+ result = strcmp(str1, str2) != 0;
+ else
+ /* bail out if allocation fails */
+ result = 1;
+
free(str1);
free(str2);
if (result)
--
1.7.10.4
next prev parent reply other threads:[~2012-07-04 5:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-04 5:34 [GIT PULL 00/16] tools lib traceevent: Pending backports of libparseevent Namhyung Kim
2012-07-04 5:35 ` [PATCH 01/16] tools lib traceevent: Let filtering numbers by string use function names Namhyung Kim
2012-07-04 5:35 ` [PATCH 02/16] tools lib traceevent: Add support for "%.*s" in bprintk events Namhyung Kim
2012-07-04 5:35 ` [PATCH 03/16] tools lib traceevent: Add support to show migrate disable counter Namhyung Kim
2012-07-04 5:35 ` [PATCH 04/16] tools lib traceevent: Fix %pM print format arg handling Namhyung Kim
2012-07-04 5:35 ` [PATCH 05/16] tools lib traceevent: Fix trace_printk for long integers Namhyung Kim
2012-07-04 5:35 ` [PATCH 06/16] tools lib traceevent: Fix printk_cmp() Namhyung Kim
2012-07-04 5:35 ` [PATCH 07/16] tools lib traceevent: Introduce extend_token() Namhyung Kim
2012-07-04 5:35 ` [PATCH 08/16] tools lib traceevent: Handle strdup failure cases Namhyung Kim
2012-07-04 5:35 ` [PATCH 09/16] tools lib traceevent: Handle realloc() failure path Namhyung Kim
2012-07-04 5:35 ` [PATCH 10/16] tools lib traceevent: Pass string type argument to args Namhyung Kim
2012-07-04 5:35 ` [PATCH 11/16] tools lib traceevent: Do not call add_event() again if allocation failed Namhyung Kim
2012-07-04 5:35 ` [PATCH 12/16] tools lib traceevent: Fix some comments Namhyung Kim
2012-07-04 5:35 ` [PATCH 13/16] tools lib traceevent: Check result of malloc() during reading token Namhyung Kim
2012-07-04 5:35 ` Namhyung Kim [this message]
2012-07-04 5:35 ` [PATCH 15/16] tools lib traceevent: Add missing break in make_bprint_args Namhyung Kim
2012-07-04 5:35 ` [PATCH 16/16] tools lib traceevent: Cleanup realloc use Namhyung Kim
2012-07-05 15:27 ` [GIT PULL 00/16] tools lib traceevent: Pending backports of libparseevent Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1341380130-23863-14-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=acme@infradead.org \
--cc=bp@alien8.de \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=namhyung@gmail.com \
--cc=paulus@samba.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®