diff options
author | Wang Nan <wangnan0@huawei.com> | 2015-03-13 13:51:54 +0100 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-03-19 17:53:28 +0100 |
commit | 0c8c20779c5d56b93b8cb4cd30ba129a927ab437 (patch) | |
tree | 834448d6d5be440844e1ba755e6cf3a5832dfec6 /tools/perf/util/parse-options.c | |
parent | perf callchain: Separate eh/debug frame offset cache. (diff) | |
download | linux-0c8c20779c5d56b93b8cb4cd30ba129a927ab437.tar.xz linux-0c8c20779c5d56b93b8cb4cd30ba129a927ab437.zip |
perf report: Don't allow empty argument for '-t'.
Without this patch, perf report cause segfault if pass "" as '-t':
$ perf report -t ""
# To display the perf.data header info, please use --header/--header-only options.
#
# Samples: 37 of event 'syscalls:sys_enter_write'
# Event count (approx.): 37
#
# Children SelfCommand Shared Object Symbol
Segmentation fault
Since -t is used to add field-separator for generate table, -t "" is
actually meanless. This patch defines a new OPT_STRING_NOEMPTY() option
generator to ensure user never pass empty string to that option.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: pi3orama@163.com
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Link: http://lkml.kernel.org/r/1426251114-198991-1-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/parse-options.c')
-rw-r--r-- | tools/perf/util/parse-options.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index 1457d6639b60..01626be2a8eb 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c @@ -37,6 +37,7 @@ static int get_value(struct parse_opt_ctx_t *p, { const char *s, *arg = NULL; const int unset = flags & OPT_UNSET; + int err; if (unset && p->opt) return opterror(opt, "takes no value", flags); @@ -114,13 +115,29 @@ static int get_value(struct parse_opt_ctx_t *p, return 0; case OPTION_STRING: + err = 0; if (unset) *(const char **)opt->value = NULL; else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) *(const char **)opt->value = (const char *)opt->defval; else - return get_arg(p, opt, flags, (const char **)opt->value); - return 0; + err = get_arg(p, opt, flags, (const char **)opt->value); + + /* PARSE_OPT_NOEMPTY: Allow NULL but disallow empty string. */ + if (opt->flags & PARSE_OPT_NOEMPTY) { + const char *val = *(const char **)opt->value; + + if (!val) + return err; + + /* Similar to unset if we are given an empty string. */ + if (val[0] == '\0') { + *(const char **)opt->value = NULL; + return 0; + } + } + + return err; case OPTION_CALLBACK: if (unset) |