Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 573709fd authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150506124647.4961.99473.stgit@localhost.localdomain


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9bc9f3b6
Loading
Loading
Loading
Loading
+20 −15
Original line number Original line Diff line number Diff line
@@ -980,6 +980,18 @@ static int parse_line_num(char **ptr, int *val, const char *what)
	return 0;
	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'.
 * Stuff 'lr' according to the line range described by 'arg'.
 * The line range syntax is described by:
 * 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;
			goto err;
		}
		}
		lr->function = name;
		lr->function = name;
	} else if (strchr(name, '.'))
	} else if (strchr(name, '/') || strchr(name, '.'))
		lr->file = name;
		lr->file = name;
	else
	else if (is_c_func_name(name))/* We reuse it for checking funcname */
		lr->function = name;
		lr->function = name;
	else {	/* Invalid name */
		semantic_error("'%s' is not a valid function name.\n", name);
		err = -EINVAL;
		goto err;
	}


	return 0;
	return 0;
err:
err:
@@ -1059,18 +1076,6 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
	return 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. */
/* Parse probepoint definition. */
static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
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");
			semantic_error("Group name is not supported yet.\n");
			return -ENOTSUP;
			return -ENOTSUP;
		}
		}
		if (!check_event_name(arg)) {
		if (!is_c_func_name(arg)) {
			semantic_error("%s is bad for event name -it must "
			semantic_error("%s is bad for event name -it must "
				       "follow C symbol-naming rule.\n", arg);
				       "follow C symbol-naming rule.\n", arg);
			return -EINVAL;
			return -EINVAL;