Skip to content

Commit 040bf9a

Browse files
plougherakpm00
authored andcommitted
Squashfs: remove deprecated strncpy by not copying the string
Squashfs copied the passed string (name) into a temporary buffer to ensure it was NUL-terminated. This however is completely unnecessary as the string is already NUL-terminated. So remove the deprecated strncpy() by completely removing the string copy. The background behind this unnecessary string copy is that it dates back to the days when Squashfs was an out of kernel patch. The code deliberately did not assume the string was NUL-terminated in case in future this changed (due to kernel changes). This would mean the out of tree patches would be broken but still compile OK. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Phillip Lougher <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Justin Stitt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 029c45b commit 040bf9a

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

fs/squashfs/namei.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,21 @@
6262
*/
6363
static int get_dir_index_using_name(struct super_block *sb,
6464
u64 *next_block, int *next_offset, u64 index_start,
65-
int index_offset, int i_count, const char *name,
66-
int len)
65+
int index_offset, int i_count, const char *name)
6766
{
6867
struct squashfs_sb_info *msblk = sb->s_fs_info;
6968
int i, length = 0, err;
7069
unsigned int size;
7170
struct squashfs_dir_index *index;
72-
char *str;
7371

7472
TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
7573

76-
index = kmalloc(sizeof(*index) + SQUASHFS_NAME_LEN * 2 + 2, GFP_KERNEL);
74+
index = kmalloc(sizeof(*index) + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
7775
if (index == NULL) {
7876
ERROR("Failed to allocate squashfs_dir_index\n");
7977
goto out;
8078
}
8179

82-
str = &index->name[SQUASHFS_NAME_LEN + 1];
83-
strncpy(str, name, len);
84-
str[len] = '\0';
85-
8680
for (i = 0; i < i_count; i++) {
8781
err = squashfs_read_metadata(sb, index, &index_start,
8882
&index_offset, sizeof(*index));
@@ -101,7 +95,7 @@ static int get_dir_index_using_name(struct super_block *sb,
10195

10296
index->name[size] = '\0';
10397

104-
if (strcmp(index->name, str) > 0)
98+
if (strcmp(index->name, name) > 0)
10599
break;
106100

107101
length = le32_to_cpu(index->index);
@@ -153,7 +147,7 @@ static struct dentry *squashfs_lookup(struct inode *dir, struct dentry *dentry,
153147
length = get_dir_index_using_name(dir->i_sb, &block, &offset,
154148
squashfs_i(dir)->dir_idx_start,
155149
squashfs_i(dir)->dir_idx_offset,
156-
squashfs_i(dir)->dir_idx_cnt, name, len);
150+
squashfs_i(dir)->dir_idx_cnt, name);
157151

158152
while (length < i_size_read(dir)) {
159153
/*

0 commit comments

Comments
 (0)