bcachefs: replace strncpy() with memcpy_and_pad in journal_transaction_name
authorRoxana Nicolescu <nicolescu.roxana@protonmail.com>
Thu, 27 Mar 2025 14:50:05 +0000 (14:50 +0000)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:13:24 +0000 (20:13 -0400)
Strncpy is now deprecated.
The buffer destination is not required to be NULL-terminated, but we also
want to zero out the rest of the buffer as it is already done in other
places.

Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: Roxana Nicolescu <nicolescu.roxana@protonmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_trans_commit.c

index 7d7e52ddde02ac3143209a891dd7cbf0b5544f0f..4297d8b5edddf7b4af3f5b389268dc6da2e51a79 100644 (file)
@@ -20,6 +20,7 @@
 #include "snapshot.h"
 
 #include <linux/prefetch.h>
+#include <linux/string_helpers.h>
 
 static const char * const trans_commit_flags_strs[] = {
 #define x(n, ...) #n,
@@ -366,7 +367,8 @@ static noinline void journal_transaction_name(struct btree_trans *trans)
        struct jset_entry_log *l =
                container_of(entry, struct jset_entry_log, entry);
 
-       strncpy(l->d, trans->fn, JSET_ENTRY_LOG_U64s * sizeof(u64));
+       memcpy_and_pad(l->d, JSET_ENTRY_LOG_U64s * sizeof(u64),
+                      trans->fn, strlen(trans->fn), 0);
 }
 
 static inline int btree_key_can_insert(struct btree_trans *trans,