Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752387AbbEJHFg (ORCPT ); Sun, 10 May 2015 03:05:36 -0400 Received: from terminus.zytor.com ([198.137.202.10]:44654 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752342AbbEJHFb (ORCPT ); Sun, 10 May 2015 03:05:31 -0400 Date: Sun, 10 May 2015 00:04:56 -0700 From: tip-bot for Masami Hiramatsu Message-ID: Cc: namhyung@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org, hpa@zytor.com, jolsa@redhat.com, hemant@linux.vnet.ibm.com, acme@redhat.com, mingo@kernel.org, dsahern@gmail.com, ananth@in.ibm.com, tglx@linutronix.de, masami.hiramatsu.pt@hitachi.com Reply-To: tglx@linutronix.de, masami.hiramatsu.pt@hitachi.com, mingo@kernel.org, acme@redhat.com, hemant@linux.vnet.ibm.com, ananth@in.ibm.com, dsahern@gmail.com, linux-kernel@vger.kernel.org, peterz@infradead.org, hpa@zytor.com, jolsa@redhat.com, namhyung@kernel.org In-Reply-To: <20150506124647.4961.99473.stgit@localhost.localdomain> References: <20150506124647.4961.99473.stgit@localhost.localdomain> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf probe: Make --line checks validate C-style function name Git-Commit-ID: 573709fdfd668423ba4202c4f1016e3cd7bdd134 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3781 Lines: 116 Commit-ID: 573709fdfd668423ba4202c4f1016e3cd7bdd134 Gitweb: http://git.kernel.org/tip/573709fdfd668423ba4202c4f1016e3cd7bdd134 Author: Masami Hiramatsu AuthorDate: Wed, 6 May 2015 21:46:47 +0900 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 8 May 2015 16:05:02 -0300 perf probe: Make --line checks validate C-style function name Fix --line to check valid C-style function name and returns a semantic error if it is not. For example, previously, --line doesn't support lazy pattern but it doesn't recognized as a semantic error. ---- # perf probe -L 'func;return*:0-10' Specified source line is not found. Error: Failed to show lines. ---- With this patch, it is correctly handled as a semantic error. ---- # perf probe -L 'func;return*:0-10' Semantic error :'func;return*' is not a valid function name. ... ---- Signed-off-by: Masami Hiramatsu Tested-by: Arnaldo Carvalho de Melo Cc: Ananth N Mavinakayanahalli Cc: David Ahern Cc: Hemant Kumar Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20150506124647.4961.99473.stgit@localhost.localdomain Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/probe-event.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 63cb7c5..4265f2e 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -980,6 +980,18 @@ static int parse_line_num(char **ptr, int *val, const char *what) return 0; } +/* Check the name is good for event, group or function */ +static bool is_c_func_name(const char *name) +{ + if (!isalpha(*name) && *name != '_') + return false; + while (*++name != '\0') { + if (!isalpha(*name) && !isdigit(*name) && *name != '_') + return false; + } + return true; +} + /* * Stuff 'lr' according to the line range described by 'arg'. * The line range syntax is described by: @@ -1048,10 +1060,15 @@ int parse_line_range_desc(const char *arg, struct line_range *lr) goto err; } lr->function = name; - } else if (strchr(name, '.')) + } else if (strchr(name, '/') || strchr(name, '.')) lr->file = name; - else + else if (is_c_func_name(name))/* We reuse it for checking funcname */ lr->function = name; + else { /* Invalid name */ + semantic_error("'%s' is not a valid function name.\n", name); + err = -EINVAL; + goto err; + } return 0; err: @@ -1059,18 +1076,6 @@ err: return err; } -/* Check the name is good for event/group */ -static bool check_event_name(const char *name) -{ - if (!isalpha(*name) && *name != '_') - return false; - while (*++name != '\0') { - if (!isalpha(*name) && !isdigit(*name) && *name != '_') - return false; - } - return true; -} - /* Parse probepoint definition. */ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) { @@ -1094,7 +1099,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) semantic_error("Group name is not supported yet.\n"); return -ENOTSUP; } - if (!check_event_name(arg)) { + if (!is_c_func_name(arg)) { semantic_error("%s is bad for event name -it must " "follow C symbol-naming rule.\n", arg); return -EINVAL; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/