From: Siddarth G Date: Tue, 25 Mar 2025 18:12:32 +0000 (+0530) Subject: tracing: Replace strncpy with memcpy for fixed-length substring copy X-Git-Tag: v6.15-rc1~141^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e0344f9564f5847dc20e245fbea67a4b262ee659;p=thirdparty%2Fkernel%2Flinux.git tracing: Replace strncpy with memcpy for fixed-length substring copy checkpatch.pl reports the following warning: WARNING: Prefer strscpy, strscpy_pad, or __nonstring over strncpy (see: https://github.com/KSPP/linux/issues/90) In synth_field_string_size(), replace strncpy() with memcpy() to copy 'len' characters from 'start' to 'buf'. The code manually adds a NUL terminator after the copy, making memcpy safe here. Link: https://lore.kernel.org/20250325181232.38284-1-siddarthsgml@gmail.com Signed-off-by: Siddarth G Signed-off-by: Steven Rostedt (Google) --- diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index 6d592cbc38e4f..969f48742d72c 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -207,7 +207,7 @@ static int synth_field_string_size(char *type) if (len == 0) return 0; /* variable-length string */ - strncpy(buf, start, len); + memcpy(buf, start, len); buf[len] = '\0'; err = kstrtouint(buf, 0, &size);