Skip to content

Commit a35454e

Browse files
committed
ext4: use memcpy() instead of strcpy()
The strcpy() function is considered dangerous and eeeevil by people who are using sophisticated code analysis tools such as "grep". This is true even when a quick inspection would show that the source is a constant string ("." or "..") and the destination is a fixed array which is guaranteed to have enough space. Make the "grep" code analysis tool happy by using memcpy() isstead of strcpy(). :-) Signed-off-by: Theodore Ts'o <tytso@mit.edu> Link: https://patch.msgid.link/20250712181249.434530-2-tytso@mit.edu Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 3658b8b commit a35454e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

fs/ext4/inline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ int ext4_inlinedir_to_tree(struct file *dir_file,
13171317
if (pos == 0) {
13181318
fake.inode = cpu_to_le32(inode->i_ino);
13191319
fake.name_len = 1;
1320-
strcpy(fake.name, ".");
1320+
memcpy(fake.name, ".", 2);
13211321
fake.rec_len = ext4_rec_len_to_disk(
13221322
ext4_dir_rec_len(fake.name_len, NULL),
13231323
inline_size);
@@ -1327,7 +1327,7 @@ int ext4_inlinedir_to_tree(struct file *dir_file,
13271327
} else if (pos == EXT4_INLINE_DOTDOT_OFFSET) {
13281328
fake.inode = cpu_to_le32(parent_ino);
13291329
fake.name_len = 2;
1330-
strcpy(fake.name, "..");
1330+
memcpy(fake.name, "..", 3);
13311331
fake.rec_len = ext4_rec_len_to_disk(
13321332
ext4_dir_rec_len(fake.name_len, NULL),
13331333
inline_size);

fs/ext4/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
29242924
de->name_len = 1;
29252925
de->rec_len = ext4_rec_len_to_disk(ext4_dir_rec_len(de->name_len, NULL),
29262926
blocksize);
2927-
strcpy(de->name, ".");
2927+
memcpy(de->name, ".", 2);
29282928
ext4_set_de_type(inode->i_sb, de, S_IFDIR);
29292929

29302930
de = ext4_next_entry(de, blocksize);
@@ -2938,7 +2938,7 @@ struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
29382938
de->rec_len = ext4_rec_len_to_disk(
29392939
ext4_dir_rec_len(de->name_len, NULL),
29402940
blocksize);
2941-
strcpy(de->name, "..");
2941+
memcpy(de->name, "..", 3);
29422942
ext4_set_de_type(inode->i_sb, de, S_IFDIR);
29432943

29442944
return ext4_next_entry(de, blocksize);

0 commit comments

Comments
 (0)