Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/ps3: refactor strncpy usage

`strncpy` is deprecated for use on NUL-terminated destination strings [1].

`make_first_field()` should use similar implementation to `make_field()`
due to memcpy having more obvious behavior here. The end result yields
the same behavior as the previous `strncpy`-based implementation
including the NUL-padding.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Geoff Levand <geoff@infradead.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230816-strncpy-arch-powerpc-platforms-ps3-repository-v1-1-88283b02fb09@google.com

authored by

Justin Stitt and committed by
Michael Ellerman
f94a84a0 9a32584b

+2 -2
+2 -2
arch/powerpc/platforms/ps3/repository.c
··· 73 73 74 74 static u64 make_first_field(const char *text, u64 index) 75 75 { 76 - u64 n; 76 + u64 n = 0; 77 77 78 - strncpy((char *)&n, text, 8); 78 + memcpy((char *)&n, text, strnlen(text, sizeof(n))); 79 79 return PS3_VENDOR_ID_NONE + (n >> 32) + index; 80 80 } 81 81