diff mbox series

set_cmdline: replace fragile/deprecated strncpy with strscpy

Message ID 20241105072007.426782-1-danielyangkang@gmail.com (mailing list archive)
State Superseded
Headers show
Series set_cmdline: replace fragile/deprecated strncpy with strscpy | expand

Commit Message

Daniel Yang Nov. 5, 2024, 7:20 a.m. UTC
Kernel docs identify strncpy as being fragile and ambiguous. Replaced
strncpy with strscpy so dest str is null terminated and not padded.

Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
---
 kernel/trace/trace_sched_switch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Steven Rostedt Nov. 12, 2024, 9:12 p.m. UTC | #1
On Mon,  4 Nov 2024 23:20:07 -0800
Daniel Yang <danielyangkang@gmail.com> wrote:

> Kernel docs identify strncpy as being fragile and ambiguous. Replaced
> strncpy with strscpy so dest str is null terminated and not padded.
> 

Already been updated:

https://lore.kernel.org/linux-trace-kernel/20241031120139.1343025-1-ruanjinjie@huawei.com/

-- Steve

> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
> ---
>  kernel/trace/trace_sched_switch.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c
> index 8a407adb0..573b5d8e8 100644
> --- a/kernel/trace/trace_sched_switch.c
> +++ b/kernel/trace/trace_sched_switch.c
> @@ -187,7 +187,7 @@ static inline char *get_saved_cmdlines(int idx)
>  
>  static inline void set_cmdline(int idx, const char *cmdline)
>  {
> -	strncpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
> +	strscpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
>  }
>  
>  static void free_saved_cmdlines_buffer(struct saved_cmdlines_buffer *s)
diff mbox series

Patch

diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c
index 8a407adb0..573b5d8e8 100644
--- a/kernel/trace/trace_sched_switch.c
+++ b/kernel/trace/trace_sched_switch.c
@@ -187,7 +187,7 @@  static inline char *get_saved_cmdlines(int idx)
 
 static inline void set_cmdline(int idx, const char *cmdline)
 {
-	strncpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
+	strscpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
 }
 
 static void free_saved_cmdlines_buffer(struct saved_cmdlines_buffer *s)