linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] tracing: use strscpy() to instead of strncpy()
@ 2023-01-09 11:39 yang.yang29
  2023-01-10  0:03 ` Masami Hiramatsu
  2023-01-24 17:17 ` Steven Rostedt
  0 siblings, 2 replies; 5+ messages in thread
From: yang.yang29 @ 2023-01-09 11:39 UTC (permalink / raw)
  To: rostedt; +Cc: mhiramat, linux-kernel, linux-trace-kernel, xu.panda, yang.yang29

From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL-terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
---
 kernel/trace/trace_events_synth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index 67592eed0be8..cd636edd045e 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -195,8 +195,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)
-- 
2.15.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-02-14 22:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-09 11:39 [PATCH linux-next] tracing: use strscpy() to instead of strncpy() yang.yang29
2023-01-10  0:03 ` Masami Hiramatsu
2023-01-24 17:17 ` Steven Rostedt
2024-10-01  1:33   ` Justin Stitt
2025-02-14 22:27   ` Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).