tracing: Replace strncpy() with strscpy() when copying comm

Replace the depreciated[1] strncpy() calls with strscpy()
when copying comm.

Link: https://github.com/KSPP/linux/issues/90 [1]

Cc: <mhiramat@kernel.org>
Cc: <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/20241031120139.1343025-1-ruanjinjie@huawei.com
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
This commit is contained in:
Jinjie Ruan 2024-10-31 20:01:39 +08:00 committed by Steven Rostedt (Google)
parent ee3685a98e
commit 242b32d807
3 changed files with 4 additions and 4 deletions

View File

@ -1921,7 +1921,7 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
max_data->critical_start = data->critical_start; max_data->critical_start = data->critical_start;
max_data->critical_end = data->critical_end; max_data->critical_end = data->critical_end;
strncpy(max_data->comm, tsk->comm, TASK_COMM_LEN); strscpy(max_data->comm, tsk->comm);
max_data->pid = tsk->pid; max_data->pid = tsk->pid;
/* /*
* If tsk == current, then use current_uid(), as that does not use * If tsk == current, then use current_uid(), as that does not use

View File

@ -1599,7 +1599,7 @@ static inline void save_comm(char *comm, struct task_struct *task)
return; return;
} }
strncpy(comm, task->comm, TASK_COMM_LEN); strscpy(comm, task->comm, TASK_COMM_LEN);
} }
static void hist_elt_data_free(struct hist_elt_data *elt_data) static void hist_elt_data_free(struct hist_elt_data *elt_data)
@ -3405,7 +3405,7 @@ static bool cond_snapshot_update(struct trace_array *tr, void *cond_data)
elt_data = context->elt->private_data; elt_data = context->elt->private_data;
track_elt_data = track_data->elt.private_data; track_elt_data = track_data->elt.private_data;
if (elt_data->comm) if (elt_data->comm)
strncpy(track_elt_data->comm, elt_data->comm, TASK_COMM_LEN); strscpy(track_elt_data->comm, elt_data->comm, TASK_COMM_LEN);
track_data->updated = true; track_data->updated = true;

View File

@ -187,7 +187,7 @@ static inline char *get_saved_cmdlines(int idx)
static inline void set_cmdline(int idx, const char *cmdline) 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) static void free_saved_cmdlines_buffer(struct saved_cmdlines_buffer *s)