All the other cases in this big switch statement use memcpy or other methods for copying string data. Since the lengths are handled manually and carefully, using strncpy() is may be misleading. It doesn't guarantee any sort of NUL-termination on its destination buffer. At any rate, it's deprecated [1] and we want to remove all its uses [2].
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 [2] Cc: linux-harden...@vger.kernel.org Signed-off-by: Justin Stitt <justinst...@google.com> --- Note: build-tested only. Found with: $ rg "strncpy\(" --- kernel/debug/kdb/kdb_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 9443bc63c5a2..8bba77b4a39c 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -368,9 +368,9 @@ static char *kdb_read(char *buffer, size_t bufsize) kdb_printf("%s", buffer); } else if (tab != 2 && count > 0) { len_tmp = strlen(p_tmp); - strncpy(p_tmp+len_tmp, cp, lastchar-cp+1); + memcpy(p_tmp+len_tmp, cp, lastchar-cp+1); len_tmp = strlen(p_tmp); - strncpy(cp, p_tmp+len, len_tmp-len + 1); + memcpy(cp, p_tmp+len, len_tmp-len + 1); len = len_tmp - len; kdb_printf("%s", cp); cp += len; --- base-commit: 026e680b0a08a62b1d948e5a8ca78700bfac0e6e change-id: 20240402-strncpy-kernel-debug-kdb-kdb_io-c-53e5ed26da3d Best regards, -- Justin Stitt <justinst...@google.com>