Thread (2 messages) 2 messages, 2 authors, 2025-03-11

Re: [PATCH] tracing/synthetic: Replace deprecated strncpy() with strscpy()

From: Steven Rostedt <rostedt@goodmis.org>
Date: 2025-03-11 12:37:06
Also in: linux-hardening, lkml

On Mon, 10 Mar 2025 21:03:58 +0100
Thorsten Blum [off-list ref] wrote:
quoted hunk ↗ jump to hunk
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index e3f7d09e5512..4b51f74897b4 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -207,8 +207,7 @@ static int synth_field_string_size(char *type)
 	if (len == 0)
 		return 0; /* variable-length string */
 
-	strncpy(buf, start, len);
-	buf[len] = '\0';
+	strscpy(buf, start, len + 1);
 
 	err = kstrtouint(buf, 0, &size);
 	if (err)
-
Looking at the code, it calculates the start and end by scanning the
string. I think it's better to just use memcpy() instead. It's not like
it's copying a random string passed in.

-- Steve
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help