Skip to content

Commit 2aa746e

Browse files
JustinStittrostedt
authored andcommitted
tracing/branch-profiler: Replace deprecated strncpy with strscpy
strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. Both of these fields want to be NUL-terminated as per their use in printk: F_printk("%u:%s:%s (%u)%s", __entry->line, __entry->func, __entry->file, __entry->correct, __entry->constant ? " CONSTANT" : "") Use strscpy() as it NUL-terminates the destination buffer, so it doesn't have to be done manually. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html Link: KSPP#90 Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Kees Cook <[email protected]> Link: https://lore.kernel.org/20240826-strncpy-kernel-trace-trace_branch-c-v1-1-b2c14f2e9e84@google.com Signed-off-by: Justin Stitt <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent e32540b commit 2aa746e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

kernel/trace/trace_branch.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ probe_likely_condition(struct ftrace_likely_data *f, int val, int expect)
7474
p--;
7575
p++;
7676

77-
strncpy(entry->func, f->data.func, TRACE_FUNC_SIZE);
78-
strncpy(entry->file, p, TRACE_FILE_SIZE);
79-
entry->func[TRACE_FUNC_SIZE] = 0;
80-
entry->file[TRACE_FILE_SIZE] = 0;
77+
strscpy(entry->func, f->data.func);
78+
strscpy(entry->file, p);
8179
entry->constant = f->constant;
8280
entry->line = f->data.line;
8381
entry->correct = val == expect;

0 commit comments

Comments
 (0)