Skip to content

Commit 086437d

Browse files
JustinStittmcgrof
authored andcommitted
kallsyms: 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. The goal is to remove its use completely [2]. namebuf is eventually cleaned of any trailing llvm suffixes using strstr(). This hints that namebuf should be NUL-terminated. static void cleanup_symbol_name(char *s) { char *res; ... res = strstr(s, ".llvm."); ... } Due to this, use strscpy() over strncpy() as it guarantees NUL-termination on the destination buffer. Drop the -1 from the length calculation as it is no longer needed to ensure NUL-termination. 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 [2] Cc: [email protected] Signed-off-by: Justin Stitt <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 8d0b728 commit 086437d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/module/kallsyms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ const char *module_address_lookup(unsigned long addr,
348348
}
349349
/* Make a copy in here where it's safe */
350350
if (ret) {
351-
strncpy(namebuf, ret, KSYM_NAME_LEN - 1);
351+
strscpy(namebuf, ret, KSYM_NAME_LEN);
352352
ret = namebuf;
353353
}
354354
preempt_enable();

0 commit comments

Comments
 (0)