]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ext4: use memcpy() instead of strcpy()
authorTheodore Ts'o <tytso@mit.edu>
Sat, 12 Jul 2025 18:12:48 +0000 (14:12 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 18 Jul 2025 03:25:21 +0000 (23:25 -0400)
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>
fs/ext4/inline.c
fs/ext4/namei.c

index 121279f84bef34c266eb58dbd674ddca79c2f56a..77e8b7707650e551b04f79e487b4479ca760b543 100644 (file)
@@ -1317,7 +1317,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, ".");
+                       memcpy(fake.name, ".", 2);
                        fake.rec_len = ext4_rec_len_to_disk(
                                          ext4_dir_rec_len(fake.name_len, NULL),
                                          inline_size);
@@ -1327,7 +1327,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, "..");
+                       memcpy(fake.name, "..", 3);
                        fake.rec_len = ext4_rec_len_to_disk(
                                          ext4_dir_rec_len(fake.name_len, NULL),
                                          inline_size);
index b82f5841c65a933a55216ffdff3d8e6c572d2a95..9913a94b6a6d360bb2f778e4c030840e1526c495 100644 (file)
@@ -2924,7 +2924,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, ".");
+       memcpy(de->name, ".", 2);
        ext4_set_de_type(inode->i_sb, de, S_IFDIR);
 
        de = ext4_next_entry(de, blocksize);
@@ -2938,7 +2938,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, "..");
+       memcpy(de->name, "..", 3);
        ext4_set_de_type(inode->i_sb, de, S_IFDIR);
 
        return ext4_next_entry(de, blocksize);