]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Replace strncpy() with strscpy()
authorYuntao Wang <ytcoode@gmail.com>
Fri, 4 Mar 2022 07:04:08 +0000 (15:04 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 8 Mar 2022 06:04:33 +0000 (22:04 -0800)
commitc8ee8945edbba9ce0b4e3313307bdd43857733ff
tree0c06340fc7c23e7edcaec27e902d871fd1183cc9
parentf98ace7acc1fbc1a2e9f19f85f7697fc1d70911f
bpf: Replace strncpy() with strscpy()

Using strncpy() on NUL-terminated strings is considered deprecated[1].
Moreover, if the length of 'task->comm' is less than the destination buffer
size, strncpy() will NUL-pad the destination buffer, which is a needless
performance penalty.

Replacing strncpy() with strscpy() fixes all these issues.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20220304070408.233658-1-ytcoode@gmail.com
kernel/bpf/helpers.c