summaryrefslogtreecommitdiff
path: root/kernel/bpf/disasm.c
diff options
context:
space:
mode:
authorJustin Stitt <justinstitt@google.com>2024-04-03 02:52:50 +0300
committerDaniel Borkmann <daniel@iogearbox.net>2024-04-03 17:57:41 +0300
commit2e114248e086fb376405ed3f89b220f8586a2541 (patch)
tree3cbcfd5ea628f560c4d4156051ea34fa00509a76 /kernel/bpf/disasm.c
parentc53908b254fcf25b05bcdf6634adb36eaccac111 (diff)
downloadlinux-2e114248e086fb376405ed3f89b220f8586a2541.tar.xz
bpf: 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. bpf sym names get looked up and compared/cleaned with various string apis. This suggests they need to be NUL-terminated (strncpy() suggests this but does not guarantee it). | static int compare_symbol_name(const char *name, char *namebuf) | { | cleanup_symbol_name(namebuf); | return strcmp(name, namebuf); | } | static void cleanup_symbol_name(char *s) | { | ... | res = strstr(s, ".llvm."); | ... | } Use strscpy() as this method guarantees NUL-termination on the destination buffer. This patch also replaces two uses of strncpy() used in log.c. These are simple replacements as postfix has been zero-initialized on the stack and has source arguments with a size less than the destination's size. Note that this patch uses the new 2-argument version of strscpy introduced in commit e6584c3964f2f ("string: Allow 2-argument strscpy()"). Signed-off-by: Justin Stitt <justinstitt@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Daniel Borkmann <daniel@iogearbox.net> 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 [2] Link: https://github.com/KSPP/linux/issues/90 Link: https://lore.kernel.org/bpf/20240402-strncpy-kernel-bpf-core-c-v1-1-7cb07a426e78@google.com
Diffstat (limited to 'kernel/bpf/disasm.c')
0 files changed, 0 insertions, 0 deletions