public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ext4: replace strcpy() with '.' assignment
@ 2025-05-19  3:54 Ethan Carter Edwards
  2025-05-19  5:58 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Ethan Carter Edwards @ 2025-05-19  3:54 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger
  Cc: linux-ext4, linux-kernel, linux-hardening, Ethan Carter Edwards

strcpy() is deprecated; assignment can be used instead which
theoretically/potentially increases speed as a function call is removed.

Straight assignment works because the strings are not null-terminated
which means they don't strictly require a str(s)cpy call.

No functional changes intended.

Link: https://github.com/KSPP/linux/issues/88
Suggested-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
There's an ongoing effort to remove calls to strcpy throughout the
kernel.

Link: https://github.com/KSPP/linux/issues/88
---
Changes in v2:
- completely remove the call to strcpy and replace it with assignment
  off of Theo's suggestion. Thanks.
- Link to v1: https://lore.kernel.org/r/20250518-ext4-strcpy-v1-1-6c8a82ff078f@ethancedwards.com
---
 fs/ext4/inline.c | 4 ++--
 fs/ext4/namei.c  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index 2c9b762925c72f2ff5a402b02500370bc1eb0eb1..f3bc8b3904a8a9b55162f002b5bd63a527b290a5 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1314,7 +1314,7 @@ int ext4_inlinedir_to_tree(struct file *dir_file,
 		if (pos == 0) {
 			fake.inode = cpu_to_le32(inode->i_ino);
 			fake.name_len = 1;
-			strcpy(fake.name, ".");
+			fake.name[0] = ".";
 			fake.rec_len = ext4_rec_len_to_disk(
 					  ext4_dir_rec_len(fake.name_len, NULL),
 					  inline_size);
@@ -1324,7 +1324,7 @@ int ext4_inlinedir_to_tree(struct file *dir_file,
 		} else if (pos == EXT4_INLINE_DOTDOT_OFFSET) {
 			fake.inode = cpu_to_le32(parent_ino);
 			fake.name_len = 2;
-			strcpy(fake.name, "..");
+			fake.name[0] = fake.name[1] = ".";
 			fake.rec_len = ext4_rec_len_to_disk(
 					  ext4_dir_rec_len(fake.name_len, NULL),
 					  inline_size);
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index e9712e64ec8f04586f5ebcd332431e6af92e4f36..c7d7c46a0b18ae109d30358c157812ac2ded200e 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -2926,7 +2926,7 @@ struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
 	de->name_len = 1;
 	de->rec_len = ext4_rec_len_to_disk(ext4_dir_rec_len(de->name_len, NULL),
 					   blocksize);
-	strcpy(de->name, ".");
+	de->name[0] = '.';
 	ext4_set_de_type(inode->i_sb, de, S_IFDIR);
 
 	de = ext4_next_entry(de, blocksize);
@@ -2940,7 +2940,7 @@ struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
 		de->rec_len = ext4_rec_len_to_disk(
 					ext4_dir_rec_len(de->name_len, NULL),
 					blocksize);
-	strcpy(de->name, "..");
+	de->name[0] = de->name[1] = '.';
 	ext4_set_de_type(inode->i_sb, de, S_IFDIR);
 
 	return ext4_next_entry(de, blocksize);

---
base-commit: 5723cc3450bccf7f98f227b9723b5c9f6b3af1c5
change-id: 20250518-ext4-strcpy-1545c6f79b51

Best regards,
-- 
Ethan Carter Edwards <ethan@ethancedwards.com>


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-05-23 22:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19  3:54 [PATCH v2] ext4: replace strcpy() with '.' assignment Ethan Carter Edwards
2025-05-19  5:58 ` kernel test robot
2025-05-19 13:56   ` Theodore Ts'o
2025-05-19  5:58 ` kernel test robot
2025-05-19 13:52 ` Kees Cook
2025-05-19 14:59   ` Theodore Ts'o
2025-05-23 12:31     ` David Laight
2025-05-23 14:24       ` Theodore Ts'o
2025-05-23 17:14         ` Kees Cook
2025-05-23 22:07           ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox