If a value for tracing file is NULL,
segment fault error can occur using strlen().
Of course, currently the function don't be given NULL value.
But write_tracing_file() can be generally used.
So add the if statement.

Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Signed-off-by: Taeung Song <[email protected]>
---
 tools/perf/builtin-ftrace.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 8df5416..0754dee 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -54,8 +54,12 @@ static int write_tracing_file(const char *name, const char 
*val)
 {
        char *file;
        int fd, ret = -1;
-       ssize_t size = strlen(val);
+       ssize_t size;
 
+       if (val == NULL)
+               return -1;
+
+       size = strlen(val);
        file = get_tracing_file(name);
        if (!file) {
                pr_debug("cannot get tracing file: %s\n", name);
-- 
2.7.4

Reply via email to