Skip to contentSkip to conversation

tracing: Use strim() to remove whitespace instead of doing it manually

PATCH In review Yuntao Wang 2 participants 2 messages Jan 21, 2022 – May 24, 2022 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: Use strim() to remove whitespace instead of doing it manually

The tracing_set_trace_write() function just removes the trailing whitespace from the user supplied tracer name, but the leading whitespace should also be removed.

In addition, if the user supplied tracer name contains only a few whitespace characters, the first one will not be removed using the current method, which results it a single whitespace character left in the buf.

To fix all of these issues, we use strim() to correctly remove both the leading and trailing whitespace.

---
 kernel/trace/trace.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
kernel/trace/trace.c +3 -5
index a569a0cb81ee..a6e77db764cf 100644
@@ -6433,7 +6433,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
 {
 	struct trace_array *tr = filp->private_data;
 	char buf[MAX_TRACER_SIZE+1];
-	int i;
+	char *name;
 	size_t ret;
 	int err;
 
@@ -6447,11 +6447,9 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
 
 	buf[cnt] = 0;
 
-	/* strip ending whitespace. */
-	for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
-		buf[i] = 0;
+	name = strim(buf);
 
-	err = tracing_set_tracer(tr, buf);
+	err = tracing_set_tracer(tr, name);
 	if (err)
 		return err;
 
Signature · 1 line
2.35.0.rc2
maintainer
#1 lore raw
Quoted 4 lines · On Fri, 21 Jan 2022 09:56:23 +0000 Yuntao Wang <[email protected]> wrote:

The tracing_set_trace_write() function just removes the trailing whitespace from the user supplied tracer name, but the leading whitespace should also be removed.

Quoted 8 lines

In addition, if the user supplied tracer name contains only a few whitespace characters, the first one will not be removed using the current method, which results it a single whitespace character left in the buf.

To fix all of these issues, we use strim() to correctly remove both the leading and trailing whitespace.

Added to my queue.

Thanks,

-- Steve