tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf
PATCH v2 1/1 tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf
strncpy() is deprecated for NUL-terminated destination buffers and must be replaced by strscpy().
See issue: https://github.com/KSPP/linux/issues/90
--- kernel/trace/trace_stack.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/trace/trace_stack.c +5 -2
@@ -3,6 +3,7 @@* Copyright (C) 2008 Steven Rostedt <[email protected]> * */ +#include <linux/string.h> #include <linux/sched/task_stack.h> #include <linux/stacktrace.h> #include <linux/security.h>
@@ -543,8 +544,10 @@ static __init int enable_stacktrace(char *str) {int len; -if ((len =str_has_prefix (str,"_filter=" ))) -strncpy (stack_trace_filter_buf, str + len,COMMAND_LINE_SIZE ); + len =str_has_prefix (str,"_filter=" ); + +if (len) +strscpy (stack_trace_filter_buf, str + len,sizeof (stack_trace_filter_buf)); stack_tracer_enabled =1 ;return 1 ;
Signature · 1 line
2.47.1
Steven Rostedt
maintainerQuoted 15 lines · On Fri, 4 Apr 2025 19:01:03 +0530 Devaansh Kumar <[email protected]>…
strncpy()is deprecated for NUL-terminated destination buffers and must be replaced bystrscpy().See issue: https://github.com/KSPP/linux/issues/90
Signed-off-by Devaansh Kumar <[email protected]>--- kernel/trace/trace_stack.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/trace/trace_stack.c +0
-0
kernel/trace/trace_stack.c line 9
Quoted 7 lines
kernel/trace/trace_stack.c +1
-0@@ -3,6 +3,7 @@* Copyright (C) 2008 Steven Rostedt <[email protected]> * */ +#include <linux/string.h> #include <linux/sched/task_stack.h> #include <linux/stacktrace.h> #include <linux/security.h>
Is string.h really needed here? And if so, please keep the upside-down x-mas tree format:
#include <linux/sched/task_stack.h>
#include <linux/stacktrace.h>
#include <linux/security.h>
#include <linux/kallsyms.h>
#include <linux/seq_file.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <linux/ftrace.h>
#include <linux/module.h>
#include <linux/sysctl.h>
#include <linux/init.h>
The includes *are* ordered.
-- Steve
Quoted 3 lines · Steven Rostedt
Is
string.hreally needed here? And if so, please keep the upside-down x-mas tree format:
My bad. It was auto added by my IDE. It is not needed.