tracing: Make sure the parsed string always terminates with '\0'
authorChangbin Du <changbin.du@intel.com>
Tue, 16 Jan 2018 09:02:30 +0000 (17:02 +0800)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Tue, 23 Jan 2018 20:57:28 +0000 (15:57 -0500)
Always mark the parsed string with a terminated nul '\0' character. This removes
the need for the users to have to append the '\0' before using the parsed string.

Link: http://lkml.kernel.org/r/1516093350-12045-4-git-send-email-changbin.du@intel.com
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Changbin Du <changbin.du@intel.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/ftrace.c
kernel/trace/trace.c
kernel/trace/trace_events.c

index 554b517c61a04d8f976b7a10975d47327c2f7bee..dabd9d167d425b20d5a8844f4f90af2ff03346ef 100644 (file)
@@ -5015,7 +5015,6 @@ int ftrace_regex_release(struct inode *inode, struct file *file)
 
        parser = &iter->parser;
        if (trace_parser_loaded(parser)) {
-               parser->buffer[parser->idx] = 0;
                ftrace_match_records(iter->hash, parser->buffer, parser->idx);
        }
 
@@ -5329,7 +5328,6 @@ ftrace_graph_release(struct inode *inode, struct file *file)
                parser = &fgd->parser;
 
                if (trace_parser_loaded((parser))) {
-                       parser->buffer[parser->idx] = 0;
                        ret = ftrace_graph_set_hash(fgd->new_hash,
                                                    parser->buffer);
                }
index cb90435e63da44a9ef3007c4d3793b2fe91b4964..58de825df19cbce0104b4904f9b28b9f11c9da29 100644 (file)
@@ -530,8 +530,6 @@ int trace_pid_write(struct trace_pid_list *filtered_pids,
                ubuf += ret;
                cnt -= ret;
 
-               parser.buffer[parser.idx] = 0;
-
                ret = -EINVAL;
                if (kstrtoul(parser.buffer, 0, &val))
                        break;
@@ -1268,6 +1266,8 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
        } else if (parser->idx < parser->size - 1) {
                parser->cont = true;
                parser->buffer[parser->idx++] = ch;
+               /* Make sure the parsed string always terminates with '\0'. */
+               parser->buffer[parser->idx] = 0;
        } else {
                ret = -EINVAL;
                goto out;
index 1b87157edbff7c42a0884a3c0f8c0fa46c9d78ee..05c7172c6667d409de1d32f48afa01752f7a30ce 100644 (file)
@@ -885,8 +885,6 @@ ftrace_event_write(struct file *file, const char __user *ubuf,
                if (*parser.buffer == '!')
                        set = 0;
 
-               parser.buffer[parser.idx] = 0;
-
                ret = ftrace_set_clr_event(tr, parser.buffer + !set, set);
                if (ret)
                        goto out_put;